我在jQuery中有以下代码-
$(".new_makes_button").click(function(){
if($(".new_makes_button:checked").length == 0) {那么,如何用$(this)替换上述代码第二行中的类选择器".new_makes_button“?我只是在寻找正确的语法。这里有几个带有"new_makes_button“类的复选框,并单击其中任何一个,我正在检查所有复选框何时未选中,然后运行以下代码。
发布于 2014-07-13 18:12:51
您可以直接查看单击的项上的选中属性,如下所示:
if (!$(this).prop("checked")) {
// code here for when the item is not checked
}一旦您有了DOM元素(在this中有),就没有必要使用进一步的选择器了,因为您可以直接检查该项的属性。
https://stackoverflow.com/questions/24725687
复制相似问题