zoukankan      html  css  js  c++  java
  • 转:[web]javascript 增加表單的input

    利用javascript增加form的input

    這是js的部份

    //用來區分不同input的name
    var element_count = 0;
     
    function add_element(obj)
    {
      element_count++;
      //先建立一個input的tag
      var new_element = document.createElement("input");
      //設定這個input的屬性
      //可以這樣用
      new_element.type = "text";
      new_element.name = "new" + element_count;
      new_element.value = element_count;
      //也可以這樣用
      new_element.setAttribute("type","text");
      new_element.setAttribute("name","new" + element_count);
      new_element.setAttribute("value",element_count);
      //最後再使用appendChild加到要加的form裡
      obj.form.appendChild(new_element);
      //換行用~ 一樣是要加到form裡
      var s = document.createElement("br");
      obj.form.appendChild(s);
    }
    

    這是html的部份

    <form name="myform">
    <input type="button" value="增加input" onclick="add_element(this)"><br />
    </form>
    
  • 相关阅读:
    哲学家进餐
    文件系统
    文件读写原理(转)
    数据库join种类
    http与https区别
    数字证书(转)
    B. Rebranding
    扩展欧几里德算法、证明及其应用
    CodeForces 7C Line
    UVALive 7147 World Cup
  • 原文地址:https://www.cnblogs.com/zelos/p/7225334.html
Copyright © 2011-2022 走看看