zoukankan      html  css  js  c++  java
  • document.createElement后面带的参数

    原来只知道document.createElement后面带HTML元素这种用法,如
      var oTD2=document.createElement("TD");
    今天要对增加的元素使用document.getElementsByName获取其数组,因此对增加的元素name属性的设置:
     var oCk1=document.createElement("INPUT");
     oCk1.type="checkbox";
     oCk1.name="ChkSel";
     //oCk1.setAttribute("name", "ChkSel");

    但以上代码却没有成功(也没有出错)。


    开头还以为是bug之类的,后来查createElement的帮助,发现一句话
    Attributes can be included with the sTag as long as the entire string is valid HTML. You should do this if you wish to include the NAME attribute at run time on objects created with the createElement method.
    就是说document.createElement带的参数不只是一个HTML元素,也可以用HTML,这样,name属性就可以加入,例如:
    var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='First Choice'>")

    因此,我的代码改成如下即可:
     var oCk1=document.createElement("<input type=\"checkbox\" name=\"ChkSel\" />");
     oTD1.appendChild(oCk1);


     

  • 相关阅读:
    Android ANR 知多少
    电源管理
    功耗分析
    手机功耗测试
    Battery Historian
    Android 电量优化
    Android手机功耗
    功耗 Log 抓取要求规范
    Android 手机无法进入系统解决方案
    定屏死机问题操作指南
  • 原文地址:https://www.cnblogs.com/yzx99/p/1274504.html
Copyright © 2011-2022 走看看