[javascript]代码库
<table class="ListProduct" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="50">序号</td>
<td width="260">选项标题</td>
<td width="50">排序</td>
<td width="50">票数</td>
<td class="norightborder"></td>
</tr>
</tbody>
<tbody id="div_add_del" name="div_add_del">
<tr style="display:none">
<td width="50"><input type="text" name="add[id][]" readonly="readonly" disabled="disabled" value="" style="width:50px;" ></td>
<td width="200">
<input type="text" name="add[item][]" value="" class="px" style="width:150px;">
</td>
<td>
<input type="text" name="add[rank][]" value="1" style="width:50px;" class="px">
</td>
<td>
<input type="text" name="add[vcount][]" value="0" style="width:50px;" class="px">
</td>
<td width="50" class="norightborder"><a href="javascript:;" onclick="delrow(this, 'div_add_del');">删除</a></td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="4" class="norightborder">
<button type="button" id="vtype" onclick="addrow('div_add_del');" class="btnGrayS vm" value="true"><strong>添加选项</strong></button>至少2项,最多15项,已经添加[<span id='aditem'></span>]项</td>
</tr>
</tbody>
</table>
<script>
var count = 1;
function addrow(tbody) {
var add = false;
var newnode;
if($$(tbody).rows.length == 1 && $$(tbody).rows[0].style.display == 'none') {
$$(tbody).rows[0].style.display = '';
newnode = $$(tbody).rows[0];
} else {
newnode = $$(tbody).rows[0].cloneNode(true);
add = true;
}
if(add) {
$$(tbody).appendChild(newnode);
}
var aditem = document.getElementById('aditem');
aditem.innerHTML=count;
if(count==15){var vtype = document.getElementById('vtype');
vtype.disabled="disabled";vtype.value="disabled";}count++;
}
function delrow(obj, tbody) {
if($$(tbody).rows.length == 1) {
var trobj = obj.parentNode.parentNode;
trobj.style.display='none';
}else{
$$(tbody).removeChild(obj.parentNode.parentNode);
}
}</script>
[代码运行效果截图]