js 动态添加input代码

时间:2023-12-23 15:13:14
<script type="text/javascript" language="javascript">

 function newNode(thisid,thisname) {
//得到当前出入的个数
var thislength=document.getElementById(thisid).getElementsByTagName('li').length; if(thislength<=5){//最多有6个input var olElement = document.getElementById(thisid);
var liElement = document.createElement('li'); var inputElement = document.createElement('input');
inputElement.type = "text";
inputElement.name = thisname; liElement.appendChild(inputElement);
olElement.appendChild(liElement); }
} </script>
html部分代码
<ul id="qqs"><li><input type="text" name="qq[]" ></li></ul>    <span style="color:#0F0; cursor:pointer; font-size:20px; font-weight:bold" onclick="javascript:newNode('qqs','qq[]')" onmouseover="this.style.color='#0000FF'" onmouseout="this.style.color='#00FF00'">⊕</span>