<!DOCTYPE html>
<html lange="en"> <!-- 设置语音 -->
<head>
<meta charset="UFT-8"> <!-- 设置编码格式 -->
<title>Title</title>
<html lange="en"> <!-- 设置语音 -->
<head>
<meta charset="UFT-8"> <!-- 设置编码格式 -->
<title>Title</title>
</head>
<body>
<input type="button" value="全选" οnclick="choseAll()"/>
<input type="button" value="反选" οnclick="revserAll()"/>
<input type="button" value="取消" οnclick="cancleAll()"/>
<table border="1">
<thead>
<tr>
<th>选项</th>
<th>IP</th>
<th>PORT</th>
</tr>
</thead>
<tbody id="td">
<tr>
<td><input type="checkbox" /></td>
<td>192.168.0.1</td>
<td>80</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>192.168.0.2</td>
<td>82</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>192.168.0.3</td>
<td>83</td>
</tr>
</tbody>
</table>
<script src="jquery-1.12.4.js"></script> <!-- 引入jq模块 -->
<script>
function choseAll(){
console.log("choseall");
/*$("#td :checkbox") 选择标签*/
$("#td :checkbox").prop('checked',true);
}
function cancleAll(){
$('#td :checkbox').prop('checked',false);
}
function revserAll1(){
/*each() JQ中的循环 在其中添加函数*/
/*prop() 函数一个参数表示获取这个属性的值 两个参数设置这个属性的值*/
$('#td :checkbox').each(function (){
console.log("revserAll");
if(this.checked){
this.checked = false;
}else{
this.checked = true;
}
})
}
/*
document.getElementById('td'); --> <tbody id="td">...</tbody>
$('#td'); -->[tbody#td, context: document, selector: "#td"]
*/
/*$(this) 将Dom对象转换成JQ的对象*/
function revserAll2(){
$('#td :checkbox').each(function (){
console.log("revserAll");
if($(this).prop('checked')){
$(this).prop('checked',false);
}else{
$(this).prop('checked',true);
}
})
}
function revserAll(){
$('#td :checkbox').each(function (){
/*三目运算符 :
条件?结果1:结果2
*/
var v = $(this).prop('checked')?false:true;
$(this).prop('checked',v);
})
}
</script>
</body>
</html>
var v = $(this).prop('checked')?false:true;
$(this).prop('checked',v);
})
}
</script>
</body>
</html>
216

被折叠的 条评论
为什么被折叠?



