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.
Two sections are compared before an error is introduced.CodeTo 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 () ;}< br> // document. getelementbyid ('delnode '). onclick = delnode;
}< br> 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;
}< br>/* function delnode () {
return false;
} */
A person with a fine mind may be able to see it at a glance, but I am not a good player. The difference is that 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 will occur.
comment. What does it mean, there is incomplete content, and the Program is invalid. This is not a complicated task, but it wastes me a long time, write it out and share it with everyone !!!