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


     

  • 相关阅读:
    MySQL/MariaDB/Percona数据库升级脚本
    systemd详解
    Nginx下Redmine2.6配置
    Linux下Python获取IP地址
    浅谈Linux内存管理机制
    深入理解PHP Opcode缓存原理
    Varnish – 高性能http加速器
    问题记录
    Java 排序报错
    记录一次数据库链接不够用被drop掉的问题
  • 原文地址:https://www.cnblogs.com/yzx99/p/1274504.html
Copyright © 2011-2022 走看看