添加或减少控件

<script type="text/javascript">

inv_lines= 0;

function invform_line_add() {

var tb= document.getElementById("invite_table");

if( !tb ){ return; }

var tr= tb.getElementsByTagName("TR");

if( !tr || tr.length == 0 ) { return; }

tr= tr[0];

tr= tr.cloneNode(true);

var i;

var inp= tr.getElementsByTagName("INPUT");

for(i=0; i<inp.length; i++) {

inp[i].value= "";

}

inp= tr.getElementsByTagName("SELECT");

for(i=0; i<inp.length; i++) {

inp[i].selectedIndex= 0;

}

tb.appendChild(tr);

inv_lines++;

}

function invform_line_del(confirm_msg) {

if( inv_lines <= 1 ) { return; }

var tb= document.getElementById("invite_table");

if( !tb ){ return; }

var tr= tb.getElementsByTagName("TR");

if( !tr || tr.length == 0 ) { return; }

var i, inp;

for(i=tr.length-1; i>=0; i--) {

inp= tr[i].getElementsByTagName("INPUT");

if(inp.length==2 && inp[0].value=="" && inp[1].value=="") {

tb.removeChild(tr[i]);

inv_lines--;

return;

}

}

if(confirm_msg && !confirm(confirm_msg)) {

return;

}

tb.removeChild(tr[tr.length-1]);

inv_lines--;

}

</script>



<body>

<form method="post" action="">

<table id="setform" cellspacing="5">

<tbody id="invite_table">

<script type="text/javascript">

inv_lines ++; 

</script>

<tr>

<td class="setparam" style="text-align:right;">name</td>

<td><input type="text" name="name[]" value="" class="setinp" style="width:200px; padding:3px;" maxlength="100" /></td>

<td class="setparam" style="text-align:right; width:80px;">email</td>

<td><input type="text" name="email[]" value="" class="setinp" style="width:280px; padding:3px;" maxlength="100" /></td>

</tr>

</tbody>

<tr>

<td></td>

<td>

<a href="javascript:;" onclick="invform_line_add();" onfocus="this.blur();" class="addaline">add</a>

<a href="javascript:;" onclick="invform_line_del();" onfocus="this.blur();" class="remaline">del</a>

</td>

</tr>

</table>

</form>

</body>
发布了11 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/liuyingsv/article/details/50914282