Js创建input并对name属性赋值

来源:互联网 发布:office软件视频教程 编辑:程序博客网 时间:2024/05/22 03:41

 

标题: 如题

描述: 如何用JavaScript动态创建input,并对name属性赋值

tag  :  js input name 改变

 

内容:

 

    

  1. /*
  2.  * 创建Input
  3.  * inputName -- name属性名称
  4.  * inputType -- input类型 如checkbox text submit radio ...
  5.  * inputValue -- input value属性值
  6.  * aDiv -- 添加input的位置
  7.  *
  8.  */
  9. function createInput(inputName, inputType, inputValue, aDiv) {
  10.     var check = document.createElement("<input name=/"" + inputName + "/" >");   //关键, 注一
  11.     check.setAttribute("type", inputType);
  12.     check.setAttribute("value", inputValue);
  13.     aDiv.appendChild(check);
  14. }

在注一位置,要把name属性一起写进去,否则input的name属性赋值将会比较麻烦(用check.name="***"修改看不到效果)