zoukankan      html  css  js  c++  java
  • JavaScript Error:unterminated comment

    最近一直在研究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,什么意思呢,就是有不完整的内容,程序就是无效的,这不是什么复杂的事情,却浪费了我很长时间,写出来与大家共勉一下!!!

  • 相关阅读:
    ubuntu 卸载干净软件(包括配置文件)
    Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?
    linux watch 命令
    [转]如何成为优秀的程序员?
    【转】css浮动元素的知识
    Hierarchical data in postgres
    【转】supervisord使用
    手动安装pip
    zoj1649-Rescue (迷宫最短路径)【bfs 优先队列】
    poj3278-Catch That Cow 【bfs】
  • 原文地址:https://www.cnblogs.com/chaofan/p/javascriptError.html
Copyright © 2011-2022 走看看