English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A beginner in Javascript, I am always tortured by small problems every day, and I have several small problems tonight.
First: Using double quotes all over causes matching errors
<input type="checkbox" onmouseover="document.getElementById("test").style.display="none":"/>
An error has been reported all the time: unexpected token "}". Checked for half a day and could not find any errors. Compared with the video, it uses single quotes
<input type="checkbox" onmouseover="document.getElementById('test').style.display="none":"/>
The error was finally eliminated after changing to single quotes, it bothered me all night long...Here is the link http://www.cnblogs.com/chinabc/archive/2010/11/19/1881947.html
Second: Incorrectly added semicolon
<div id="test" class="test"1" onmouseover="toYellow()" ;onmouseout="toRed()";>change</div>
An extra semicolon was written, causing the code after the semicolon not to execute
Third: Too many parentheses after the function name
<script> function toYellow() { document.getElementById("test").className = "test"2"; } function toRed() { document.getElementById("test").className = "test"1"; } document.getElementById("test").onmouseover = toYellow(); document.getElementById("test").onmouseout = toRed(); </script>
After removing the parentheses after toYellow() and toRed(), the code executes normally
Viertens: Änderung der checked-Eigenschaft von Checkboxen
Drei Schaltflächen zur Realisierung der Auswahl, Auswahl und Umkehrung von Checkboxen.
!DOCTYPE html <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button id="btn">Alles auswählen</button> <button id="nobtn">Nichts auswählen</button> <button id="inverse">Umkehren</button><br /> <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>
Diese Artikel sprechen weiter über häufige Fehler in JavaScript und ihre Lösungen. Dies ist alles, was der Autor den Lesern zur Verfügung stellt. Es wird hoffen, dass es den Lesern als Referenz dient und dass alle die Anleitung unterstützen.