JavaScript Error:unterminated comment
來源:程序員人生 發(fā)布時(shí)間:2014-06-15 17:33:17 閱讀次數(shù):3901次
最近一直在研究JavaScript中的DOM(文檔對象模型),當(dāng)然,不能說是研究了,頂多也就是一個(gè)學(xué)習(xí)吧,至于DOM的邏輯語法倒并不是很難的,只是自己在編碼是難免要出現(xiàn)一些小的錯(cuò)誤,這里不好用誤差一詞。
引入錯(cuò)誤之前先比較兩段代碼,看看有什么區(qū)別沒有:
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);//建立文本節(jié)點(diǎn)
var newGraf=document.createElement('p');//建立元素節(jié)點(diǎn)
newGraf.appendChild(newText);//將文本文本添加到元素內(nèi)
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);//建立文本節(jié)點(diǎn)
var newGraf=document.createElement('p');//建立元素節(jié)點(diǎn)
newGraf.appendChild(newText);//將文本文本添加到元素內(nèi)
var docBody=document.getElementsByTagName('body')[0];
docBody.appendChild(newGraf);
document.getElementById('textArea').value="";
return false;
}
/*function delNode(){
return false;
}*/
心細(xì)的人可能一眼就能夠看的出來,可是我不屬于這一類優(yōu)秀的選手,其實(shí)區(qū)別就是在于函數(shù)function delNode()處,第一個(gè)是/*function delNode(){ return false;},第二個(gè)是/*function delNode(){return false;}*/,哈哈區(qū)別就是在于/**/注釋符是不是寫完整了,如果沒有沒有寫完整就會出現(xiàn)JavaScript Error:unterminated comment,什么意思呢,就是有不完整的內(nèi)容,程序就是無效的,這不是什么復(fù)雜的事情,卻浪費(fèi)了我很長時(shí)間,寫出來與大家共勉一下。
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈