<html>
<head>
<title>
删除整个表单&删除表单中的元素
</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var row_count = 0;
//添加一行
function addNew()
{
var table1 = $('#table1');
var firstTr = table1.find('tbody>tr:first');
var row = $("<tr></tr>");
var td = $("<td></td>");
td.append($("<input type='text' id='CheckBox"+row_count+"' name='count' value='New'><b>CheckBox"+row_count+"</b> <input type='button' value='Add' onclick='addline("+row_count+");'> <input type='button' value='Delete' onclick='del("+row_count+");'>")
);
row.append(td);
table1.append(row);
row_count++;
}
//删除一行
function del(row_count)
{
//var checked = $("input[type='checkbox'][name='count']");
//$(checked).each(function(){
//if($(this).attr("checked")==true) //注意:此处判断不能用$(this).attr("checked")==‘true'来判断。
//{
//$(this).parent().parent().remove();
//}
//});
var table1 = $('#table1');
var currval = "CheckBox"+row_count;
$("#CheckBox"+row_count).each(function(){
var id = $(this).attr('id');
if(id==currval){
$(this).parent().parent().remove();
}
});
}
var td_count=0;
//在行里增加一行
function addline(row_count){
var table1 = $('#table1');
var currval = "CheckBox"+row_count;
$("#CheckBox"+row_count).each(function(){
var id = $(this).attr('id');
if(id==currval){
$(this).parent().append($("</br> <input type='text' id='CheckBoxTd"+td_count+"' name='count' value='New'><b>CheckBoxTd"+td_count+"</b><input type='button' value='Delete' onclick='delline("+td_count+");'>")
);
}
td_count++;
});
}
//行中删除一行
function delline(td_count){
//var checked = $("input[type='checkbox'][name='count']");
//var currid = "CheckBoxTd"+td_count;
//$(checked).each(function(){
//if($(this).attr("checked")==true && $(this).attr('id')==currid)
//注意:此处判断不能用$(this).attr("checked")==‘true'来判断。
//{
//$(this).parent().parent().remove();
//}
//});
$("#CheckBoxTd"+td_count).remove();
}
</script>
</head>
<body>
<input type="button" value="Add" onclick="addNew();">
<!--<input type="button" value="Delete" onclick="del();"> -->
<div id="rightcontent">
<table id="table1" cellspacing="3" cellpadding="3" border="1">
<tbody>
<tr>
<th>
Add new row,then test the delete function.
</th>
</tr>
</tbody>
</table>
</div>
<marquee onmouseover=this.stop() onmouseout=this.start() behavior=alternate><b>author:jw QQ:794333914</b></marquee>
</body>
</html>