繁体   English   中英

jQuery:如何找到前一个复选框被选中

[英]jQuery: how to find that prevous checkbox is checked

我有一个代码,每个选中/取消选中复选框分别添加/减去一定数量。 一切正常,但是当第一个复选框离开“选中”并且我按下一秒钟时,然后我“取消选中”第一个复选框,但脚本没有减去一定数量。 我想创建 if, that can match the previous checkbox and present (it is different),如果它不同,将首先带走一定数量的 this。 这是我的 if 指令( lastClicked.find('input[type=checbox]').attr("checked")不起作用)

if(!((lastClicked.length == $(this).length && lastClicked.length == lastClicked.filter($(this)).length) || lastClicked==="") && lastClicked.find('input[type=checbox]').attr("checked"))

这是代码: https : //jsfiddle.net/3p5z6zov/

使用 prop() 而不是 attr()

►如果您使用的是 jQuery 1.6 或更高版本,请使用 prop() 而不是 attr()

lastClicked.find('input[type=checbox]').prop("checked")

当您使用prop() 时,返回的值将是布尔值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM