html <div id="org"></div> //注意:id不能寫在button上,js獲取不到button的id(可能是我們公司的框架的原因)
<input type="button" onclick="add1();" value="添加" />
script <script type="text/javascript"> function add1(){ var input1 = document.createElement('input'); input1.setAttribute('type', 'text'); input1.setAttribute('name', 'organizers[]'); input1.setAttribute('class', 'git'); var btn1 = document.getElementById("org"); btn1.insertBefore(input1,null); } </script>