日期:2014-05-16  浏览次数:20465 次

关于js创建table时IE和火狐的区别
关于js创建table时IE和火狐的区别 收藏
在做项目的时候,有个需求是:点一个按钮要添加一个table表单。
部分代码如下(其中surveyIdIndex,optionIdIndex,optionPIdIndex是全局变量):

          var obj = document.getElementById("surveyid");
        
          var tableNode = document.createElement("table");
          tableNode.setAttribute("width", "100%");
          tableNode.setAttribute("border", 0);
          tableNode.setAttribute("cellpadding", 0);
          tableNode.setAttribute("cellspacing", 0);
          tableNode.setAttribute("id", "surveyTable" + surveyIdIndex);
        
          // 第一行
          var row1Node = document.createElement("tr");
          var th1Node = document.createElement("th");
          th1Node.appendChild(document.createTextNode("调查题目" + (surveyIdIndex + 1) + ":"));
          row1Node.appendChild(th1Node);
        
          var td1Node = document.createElement("td");
          var textFiled1 = document.createElement("input");
          textFiled1.setAttribute("name", "surveyTitle_" + surveyIdIndex);
          textFiled1.setAttribute("type", "text");
          textFiled1.setAttribute("id", "title");
          //textFiled1.setAttribute("class", "input400");
          if( !window.addEventListener){ // IE
           textFiled1.className="input400";
          }else{    // FF

           textFiled1.setAttribute("class", "input400");
          }
          td1Node.appendChild(textFiled1);
        
          var textFiled_1 = document.createElement("input");
          textFiled_1.setAttribute("name", "add");
          textFiled_1.setAttribute("type", "button");
          textFiled_1.setAttribute("value", " - ");
        
          if( !window.addEventListener){ // IE
           textFiled_1.className="add2";
           textFiled_1.attachEvent("onclick", function(){delete_newsurvey(tempSurvyIndex);});
          }else{    // FF
           textFiled_1.setAttribute("class", "add2");
           textFiled_1.addEventListener('click', function(