最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

JQuery更改属性JQ对象循环each全选反选三元运算

来源:动视网 责编:小采 时间:2020-11-27 20:16:24
文档

JQuery更改属性JQ对象循环each全选反选三元运算

JQuery更改属性JQ对象循环each全选反选三元运算: <!doctype html> <html lang=en> <head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0> <meta http-equi
推荐度:
导读JQuery更改属性JQ对象循环each全选反选三元运算: <!doctype html> <html lang=en> <head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0> <meta http-equi


<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>Document</title>
</head>
<body>
 <table border="1">
 <thead>
 <tr>
 <th>选项</th>
 <th>ip</th>
 <th>port</th>
 </tr>
 </thead>
 <tbody id="i1">
 <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>
 <input type="button" value="all" onclick="checkAll()">
 <input type="button" value="rev" onclick="reverse()">
 <input type="button" value="can" onclick="checkNone()">
</body>
<script src="jquery-3.2.1.js">
</script>
<script>
 function checkAll () {
 $('#i1 input').prop('checked', true)
// $(':checkbox').prop('checked', true)
// 实际上, 这两条都是一样的.$带出的JQuery对象只能是列表, 且是标签列表.
 }
 function checkNone () {
 $('#i1 input').prop('checked',false)
 }
// function reverse() {
// $('#i1 input').each(function (k) {
// console.log(k,this);
// })
 function reverse() {
 $('#i1 input').each(function () {
 //三元运算, 实现反选, 选中的不选, 没选的选中
 var v = (this).prop('checked')?false:true;
 $(this).prop('checked',v)
 })
 }
</script>
</html>

在反选里面, 我们不需要用到for循环, 而用封装好的.each(function(k){})

.each里的函数的参数k, 实际上是下标(索引序号)

function reverse() {
 $('#i1 input').each(function (k) {
 console.log(k,this);
 })

输出的结果包含:

k? :? 0 1 2 3

this: 所有inputs里面的每一个需要循环的input子标签, 而所有的this实际上都是DOM对象而不是JQ对象

如果要把this 转为JQ对象, 需要用$(this)包起来

三元运算:

var v = 条件? 真值:假值

学术或足球分析交流微信:chinamaths(进讨论组)

Don't hesitate to comment or add a like??? -??? Yours Bill
Bill's技术博客 足球分析博客 足彩数据视频
比尔极客日志_博客园 比尔足球数据_网易博客 足彩TV_优酷
比尔极客日志_CSDN 比尔足球数据_新浪博客 足彩TV_搜狐视频
比尔极客日志_51CTO 比尔足球数据_新浪微博 足彩TV_喜马拉雅
比尔极客日志_开源中国 比尔足球数据_官方URL 足彩TV_56视频
比尔极客日志_GitHub 比尔足球数据_头条号 :zucai99

文档

JQuery更改属性JQ对象循环each全选反选三元运算

JQuery更改属性JQ对象循环each全选反选三元运算: <!doctype html> <html lang=en> <head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0> <meta http-equi
推荐度:
标签: 更改 改变 对象
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top