I have been studying the DOM (Document Object Model) in JavaScript recently. Of course, it cannot be said that it is a study. At most, it is just a study. It is not very difficult to understand the logic Syntax of DOM, it is only possible that some small errors will inevitably occur during encoding. Here, it is difficult to use the word "error.
Before introducing an error, compare two sections of code to see if there is any difference:
1
Window. onload = initAll;
Function initAll (){
Document. getElementById ('form1'). onsubmit = function () {return addNode ();}
// Document. getElementById ('delnode'). onclick = delNode;
}
Function addNode (){
Var inText = document. getElementById ('textarea '). value;
Var newText = document. createTextNode (inText); // create a text node
Var newGraf = document. createElement ('P'); // create an element node
NewGraf. appendChild (newText); // Add text to the element
Var docBody = document. getElementsByTagName ('body') [0];
DocBody. appendChild (newGraf );
Document. getElementById ('textarea '). value = "";
Return false;
}
/* Function delNode (){
Return false;
}
2
Window. onload = initAll;
Function initAll (){
Document. getElementById ('form1'). onsubmit = function () {return addNode ();}
// Document. getElementById ('delnode'). onclick = delNode;
}
Function addNode (){
Var inText = document. getElementById ('textarea '). value;
Var newText = document. createTextNode (inText); // create a text node
Var newGraf = document. createElement ('P'); // create an element node
NewGraf. appendChild (newText); // Add text to the element
Var docBody = document. getElementsByTagName ('body') [0];
DocBody. appendChild (newGraf );
Document. getElementById ('textarea '). value = "";
Return false;
}
/* Function delNode (){
Return false;
}*/
A person with a fine mind may be able to see it at a glance, but I don't belong to this type of excellent player. The difference is that the function delNode, the first is/* function delNode () {return false;}, and the second is/* function delNode () {return false ;}*/, haha, the difference is:/**/whether the annotator is completely written. If it is not completely written, JavaScript Error: unterminated comment may occur. What does it mean that there is incomplete content, the program is invalid. This is not a complicated task, but it wastes me a long time and I will share it with you.