利用jQuery实现全选、反选、删除和添加
2013-05-06 15:19
676 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
img
{
width:50px; height:50px;
}
table
{
width:600px; height:400px;
}
table tr td{ border:solid 1px #eee;}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#Checkbox7').click(function () {
//实现全选反选功能
if (this.checked) {
$('table tr td input[type=checkbox]').attr('checked', true);
}
else { $('table tr td input[type=checkbox]').attr('checked', false); }
})
//实现反选功能
$('#Checkbox8').click(function () {
$('table tr td input[type=checkbox]').each(function () {
this.checked = !this.checked;
})
})
$('#Button1').click(function () {
$("input:checked").each(function () {
$(this).parent().parent().remove();
});
})
$('#Button2').click(function () {
$('#tb1').append('<tr><td><input type="checkbox" /><td>' + Text1.value + '</td><td>' + Text2.value + '</td><td>' + Text3.value + '</td><td>' + Text4.value + '</td><td>' + Text5.value + '</td></tr>')
})
})
</script>
</head>
<body>
<div id="div1">
<input id="Checkbox7" type="checkbox" />全选<input id="Checkbox8" type="checkbox" />反选
<input id="Button1" type="button" value="删除" /><input id="Button2" type="button" value="添加" /></div>
<table id="tb1">
<tr id="first"><td>操作</td><td>班级</td><td>姓名</td><td>薪水</td><td>就业单位</td><td>是否转正</td></tr>
<tr id="0"><td><input id="Checkbox1" type="checkbox" /></td><td>2010级NET班</td><td>安宁</td><td>5000</td><td>北京联想</td><td>是</td></tr>
<tr id="1"><td><input id="Checkbox2" type="checkbox" /></td><td>2010级NET班</td><td>赵四</td><td>3000</td><td>北京联想</td><td>否</td></tr>
<tr id="2"><td><input id="Checkbox3" type="checkbox" /></td><td>2010级Java班</td><td>王红</td><td>4000</td><td>百度</td><td>是</td></tr>
<tr id="3"><td><input id="Checkbox4" type="checkbox" /></td><td>2010级PHP班</td><td>王五</td><td>3000</td><td>北京红星</td><td>否</td></tr>
<tr id="4"><td><input id="Checkbox5" type="checkbox" /></td><td>2010级3G班</td><td>里斯</td><td>6000</td><td>谷歌</td><td>是</td></tr>
</table>
姓名:<input id="Text1" type="text" />
班级:<input id="Text2" type="text" />
薪水:<input id="Text3" type="text" />
就业单位:<input id="Text4" type="text" />
是否转正:<input id="Text5" type="text" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
img
{
width:50px; height:50px;
}
table
{
width:600px; height:400px;
}
table tr td{ border:solid 1px #eee;}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#Checkbox7').click(function () {
//实现全选反选功能
if (this.checked) {
$('table tr td input[type=checkbox]').attr('checked', true);
}
else { $('table tr td input[type=checkbox]').attr('checked', false); }
})
//实现反选功能
$('#Checkbox8').click(function () {
$('table tr td input[type=checkbox]').each(function () {
this.checked = !this.checked;
})
})
$('#Button1').click(function () {
$("input:checked").each(function () {
$(this).parent().parent().remove();
});
})
$('#Button2').click(function () {
$('#tb1').append('<tr><td><input type="checkbox" /><td>' + Text1.value + '</td><td>' + Text2.value + '</td><td>' + Text3.value + '</td><td>' + Text4.value + '</td><td>' + Text5.value + '</td></tr>')
})
})
</script>
</head>
<body>
<div id="div1">
<input id="Checkbox7" type="checkbox" />全选<input id="Checkbox8" type="checkbox" />反选
<input id="Button1" type="button" value="删除" /><input id="Button2" type="button" value="添加" /></div>
<table id="tb1">
<tr id="first"><td>操作</td><td>班级</td><td>姓名</td><td>薪水</td><td>就业单位</td><td>是否转正</td></tr>
<tr id="0"><td><input id="Checkbox1" type="checkbox" /></td><td>2010级NET班</td><td>安宁</td><td>5000</td><td>北京联想</td><td>是</td></tr>
<tr id="1"><td><input id="Checkbox2" type="checkbox" /></td><td>2010级NET班</td><td>赵四</td><td>3000</td><td>北京联想</td><td>否</td></tr>
<tr id="2"><td><input id="Checkbox3" type="checkbox" /></td><td>2010级Java班</td><td>王红</td><td>4000</td><td>百度</td><td>是</td></tr>
<tr id="3"><td><input id="Checkbox4" type="checkbox" /></td><td>2010级PHP班</td><td>王五</td><td>3000</td><td>北京红星</td><td>否</td></tr>
<tr id="4"><td><input id="Checkbox5" type="checkbox" /></td><td>2010级3G班</td><td>里斯</td><td>6000</td><td>谷歌</td><td>是</td></tr>
</table>
姓名:<input id="Text1" type="text" />
班级:<input id="Text2" type="text" />
薪水:<input id="Text3" type="text" />
就业单位:<input id="Text4" type="text" />
是否转正:<input id="Text5" type="text" />
</body>
</html>
相关文章推荐
- JQuery实现添加删除数据全选反选隔行变色二级联动
- Jquery 实现动态添加table tr 和删除tr 以及checkbox的全选 和 获取添加TR删除TR后的数据
- 使用JQuery实现全选、反选、添加和删除功能
- jQuery实现添加,批量删除,全选
- jquery实现全选、反选以及删除、添加等功能
- jQuery实现动态添加和删除一个div
- JQuery实现下拉框的选择 与当CheckBox为服务器控件时如何获取值的操作,实现全选与删除
- 利用jquery给指定的table动态添加一行、删除一行
- jQuery添加删除,全选反选,批量删除
- Angularjs实现购物车功能(按钮增减数量、添加、全选、删除、批量删除、结算)
- Jquery实现代码列表,包含全选删除图片的放大
- 利用jquery给指定的table动态添加一行、删除一行
- jquery实现动态添加和删除表格
- Jquery 实现动态加入table tr 和删除tr 以及checkbox的全选 和 获取加入TR删除TR后的数据
- JQuery和JS怎样实现淘宝购物车的添加和删除?
- jquery动态添加删除div 具体实现
- Jquery动态添加 删除 操作实现
- 利用jquery插件中的拖拽与放置实现的相册效果,可以删除和恢复
- jQuery学习: 实现select multiple左右添加和删除功能