When you are a beginner in Javascript, you are always tortured by very small problems for a long time every day, and there will be several small problems tonight.
First: Use double quotes all to cause matching errors
<input type="checkbox" onmouseover="document.getElementById("test").style.display="none":"/>The error has been reported when changing the career: unexpected toke "}". I checked for a long time and found no errors. I found that the video was filled with single quotes.
<input type="checkbox" onmouseover="document.getElementById('test').style.display="none":"/>After changing to single quotes, the error was finally eliminated, which troubled me all night. . Attach the link http://www.cnblogs.com/chinabc/archive/2010/11/19/1881947.html
Second: Adding a semicolon by mistake
<div id="test" onmouseover="toYellow()" ; onmouseout="toRed()";>change</div>
Write an extra semicolon, resulting in the code after the semicolon not being executed
Third: Write more brackets after the function name
<script> function toYellow(){ document.getElementById("test").className="test2"; } function toRed(){ document.getElementById("test").className="test1"; } document.getElementById("test").onmouseover=toYellow(); document.getElementById("test").onmouseout=toRed(); </script>But after removing the brackets after toYellow() and toRed(), it will be executed normally
Fourth: Modify the checked attribute of checkbox
Use three buttons to achieve the selection, selection, and selection of checkbox.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button id="btn">Select all</button> <button id="nobtn">Not all</button> <button id="inverse">Reselect</button><br /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <script> var btn=document.getElementById("btn"); var input=document.getElementsByTagName("input"); btn.onclick=function(){ for(var i=0;i<input.length;i++){ input[i].checked="checked"; } } var nobtn=document.getElementById("nobtn"); nobtn.onclick=function(){ for(var i=0;i<input.length;i++){ input[i].checked=false; } } var inverse=document.getElementById("inverse"); inverse.onclick=function(){ for(var i=0;i<input.length;i++){ if(input[i].checked==false){ input[i].checked=true; }else{ input[i].checked=false; } } } </script> </body> </html>The above article will talk about common javascript errors and solutions. This is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.