<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<form>
<div class="biaodan">
<p><input type="checkbox" name="" value="" id="checkedAll">全选</p>
<input type="checkbox" name="c" value="1"><br>
<input type="checkbox" name="c" value="2"><br>
<input type="checkbox" name="c" value="3"><br>
<input type="checkbox" name="c" value="4"><br>
<input type="checkbox" name="c" value="5"><br>
</div>
<a href="javascript:void()" onclick="getValues()">删除选中</a>
<input type="button" name="" value="反选" onclick="checkedFan()">
<a href="javascript:changeWindow()">跳转地址</a>
</form>
</body>
<script type="text/javascript">
// 删除选中
function getValues () {
if (confirm("确认删除吗?"))
{
var a = document.getElementsByName('c');
var b = '';
for (var i = 0; i < a.length; i++) {
if (a[i].checked)
b += a[i].value + ',';
}
if (b == '')
{
alert("没有选中任何数据");
}
else
{
this.location = "http://www.baidu.com?ids=" + b;
}
}
}
// 全选
window.onload = function () {
document.getElementById("checkedAll").onclick = function () {
var a = document.getElementsByName('c');
for (var i = 0; i < a.length; i++) {
a[i].checked = this.checked; // 所有的checked和全选按钮的checked状态保持一致
}
}
}
// 反选
function checkedFan() {
var a = document.getElementsByName('c');
for (var i = 0; i < a.length; i++) {
a[i].checked = !a[i].checked; // 将checked设为当前的相反值
}
}
// 点击链接跳转
function changeWindow() {
window.location = "http://www.baidu.com";
}
</script>
</html>