您的位置:首页 > Web前端 > JQuery

利用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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: