關於jQuery選單全選,反選,取消功能很普遍,本文小編就為大家帶來一篇jQuery選單實例(全選,反選,取消)。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧,希望能幫助大家。
廢話不多說,直接上程式碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="button" value="全选" onclick="checkAll()">
<input type="button" value="反选" onclick="reverseAll()">
<input type="button" value="取消" onclick="cancleAll()">
<table border="1">
<thead>
<tr>
<th>选择</th>
<th>IP</th>
<th>端口</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"></td>
<td>1.1.1.1</td>
<td>80</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>1.1.1.1</td>
<td>80</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>1.1.1.1</td>
<td>80</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>1.1.1.1</td>
<td>80</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>1.1.1.1</td>
<td>80</td>
</tr>
</tbody>
</table>
<script type="text/javascript" src='jquery-3.2.1.js'></script>
<script type="text/javascript">
function checkAll(){
$(':checkbox').prop('checked',true);
}
function cancleAll() {
$(':checkbox').prop('checked',false);
}
function reverseAll(){
$(':checkbox').each(function(){
var v = $(this).prop('checked')? false:true; /*三元运算: var v = 条件? 真值:假值*/
$(this).prop('checked',v)
})
}
</script>
</body>
</html>相關推薦:
使用jquery選單外掛程式HoverTree仿京東無限選單_jquery
#以上是jQuery選單全選,反選,取消實例解析的詳細內容。更多資訊請關注PHP中文網其他相關文章!