• 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);


     

  • 相关阅读:
    liunx命令二
    移动App专项测试
    web安全性测试用例
    jmeter分布式测试的坑(转)
    全新linux中通过编译方式安装nginx
    Centos的yum源更换为国内的阿里云源
    配置spotlight连接linux服务器
    linux创建新用户并给予root权限
    linux下安装sar
    liunx中安装禅道
  • 原文地址:https://www.cnblogs.com/yzx99/p/1274504.html
Copyright © 2020-2023  润新知