JavaScript Error:unterminated comment

來源:互聯網
上載者:User

最近一直在研究JavaScript中的DOM(文件物件模型),當然,不能說是研究了,頂多也就是一個學習吧,至於DOM的邏輯文法倒並不是很難的,只是自己在編碼是難免要出現一些小的錯誤,這裡不好用誤差一詞。

引入錯誤之前先比較兩段代碼,看看有什麼區別沒有:

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);//建立文本節點
 
 var
newGraf=document.createElement('p');//建立元素節點
 newGraf.appendChild(newText);//將文本文本添加到元素內
 
 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);//建立文本節點
 
 var
newGraf=document.createElement('p');//建立元素節點
 newGraf.appendChild(newText);//將文本文本添加到元素內
 
 var
docBody=document.getElementsByTagName('body')[0];
 docBody.appendChild(newGraf);
 document.getElementById('textArea').value="";
 
 return
false;
 }
/*function delNode(){
   return false;
 }*/

心細的人可能一眼就能夠看的出來,可是我不屬於這一類優秀的選手,其實區別就是在於函數function delNode()處,第一個是/*function
delNode(){ return false;},第二個是/*function delNode(){return
false;}*/,哈哈區別就是在於/**/注釋符是不是寫完整了,如果沒有沒有寫完整就會出現JavaScript Error:unterminated
comment,什麼意思呢,就是有不完整的內容,程式就是無效的,這不是什麼複雜的事情,卻浪費了我很長時間,寫出來與大家共勉一下!!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.