0
おはよう、htmlページのチェックボックスをチェックしてください
スクリプトを使用してHTMLページのチェックボックスにチェックを入れようとしています。 、コラム37:5
SCRIPT5007:未定義またはnull参照 ファイルの 'チェックする' プロパティを設定することができません:ajax3、ライン
は残念ながら、私は、次のエラーメッセージが表示されます
私のコードで何が問題になったのか考えていますか?
ありがとう、素晴らしい日曜日です。
ローラン
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Demo for Ajax Auto Refresh</title> <link rel="stylesheet" type="text/css" href="css/mystyle_day.css" /> <script src="jquery-2.1.3.min.js"></script> <script> /* AJAX request to checker */ function check(){ $.ajax({ type: 'POST', url: 'checker.php', dataType: 'json', data: { counter:$('#message-list').data('counter') } }).done(function(response) { /* update counter */ $('#message-list').data('counter',response.current); /* check if with response we got a new update */ if(response.update==true){ $('#message-list').html(response.news); sayHello(); } }); } //Every 1 sec check if there is new update setInterval(check,1000); </script> <script> function sayHello(){ //console.log("Coucou"); check(); } function check() { document.getElementById("chk1").checked = true; } function uncheck() { document.getElementById("chk1").checked = false; } </script> </head> <body> <div id="message-list" data-counter="<?php echo (int)$db->check_changes();?>"> </div> <input type="checkbox" name="chk1" id="chk1"> Living room<br> <input type="checkbox" name="chk2" id="chk2"> Entrance<br> <input type="checkbox" name="chk3" id="chk3"> Kitchen<br> </body> </html>
チェックボックスには「id」属性はありません。 – gcampbell
'value =" chk1 "の代わりに' id = "chk1" 'を使用してください。 – nmnsud
大変ありがとうございます。上記のコードを修正しました。 – Laurent