2012-01-02 5 views
2

こんにちは、私は正しく私のjavascriptコード内のhtmlを表示するために私のコードを取得することに問題があります。基本的には、変数hundoが3に等しいかどうかをチェックしてから、スクリプトにフォームを表示させます。 hundoが3のときに警告メッセージを表示するようにコードをテストしましたが、document.writeを使用すると動作しません。私の推測では、あなたのdocument.writeで使用している引用符を交互にする必要があります...問題があるjavascriptのトラブルでhtmlを使用していますか?

<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write("<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>"); 
document.close(); 
} 
}, 1000); 
</script> 

答えて

1

です:

document.write('<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>'); 

問題は、あなただけの引用符の1種類を使用していることで、だから、javascriptは、未定義のjavascriptオブジェクトより"<form action="を見ています。insert.phpは、それらの間にオペレータを入れずに起動します。

+0

あなたは完全に理にかなっていると言うことは何まだそれはまだ動作していません。 – Twister

+0

「それはまだ動作していません」 - 意味は?エラーコンソールは何を言いますか? – Oded

+0

エラーコンソールには、hundo = 3のときにフォームが表示されません。 – Twister

1

問題は、あなたのdocument.write内の文字列は、自分自身を閉じている、これは動作します

<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write('<form action="insert.php" method="post"> 
    Link URL: <input type="text" name="linkurl" /> 
    <input type="submit" /> 
</form>'); 
document.close(); 
} 
}, 1000); 
</script> 
1
<script> 
setInterval(function(){ 
if(hundo == '3'){ 
document.open(); 
document.write('<form action="insert.php" method="post"> 
Link URL: <input type="text" name="linkurl" /> 
<input type="submit" /> 
</form>'); 
document.close(); 
} 
}, 1000); 
</script> 

「」で囲んしてみてください。.. :)

関連する問題