Jquery 检查复选框上是否存在类

Jquery 检查复选框上是否存在类,jquery,Jquery,这不起作用 $(".gradeA, .gradeU").find(":checkbox").click(function() { if (this.checked === false) { return; } if (this.hasClass("toggler")) { return; } 最后一行失败,但我需要检查是否有此复选框 <input type="checkbox" name="myCB" value="A" class="toggler" />Couldn't fin

这不起作用

$(".gradeA, .gradeU").find(":checkbox").click(function() {
if (this.checked === false) { return; }
if (this.hasClass("toggler")) { return; }
最后一行失败,但我需要检查是否有此复选框

<input type="checkbox" name="myCB" value="A" class="toggler" />Couldn't find the Venue<br />
找不到场地
hasClass()
jQuery
对象的成员方法。因此,您需要将
this
包含在
$()
函数中,否则您将尝试调用DOM对象上的
hasClass()
方法,该对象没有
hasClass()
作为成员函数

this
作为参数传递给
jQuery
对象(通常缩写为
$
)将返回一个
jQuery
对象,该对象确实具有
hasClass()
作为成员方法,然后每个人都很高兴,小精灵可以再次围着篝火跳舞

if (this.hasClass("toggler")) { return; }    //Your Code, wrong.
if ($(this).hasClass("toggler")) { return; } //My Code, right.
hasClass()
jQuery
对象的成员方法。因此,您需要将
this
包含在
$()
函数中,否则您将尝试调用DOM对象上的
hasClass()
方法,该对象没有
hasClass()
作为成员函数

this
作为参数传递给
jQuery
对象(通常缩写为
$
)将返回一个
jQuery
对象,该对象确实具有
hasClass()
作为成员方法,然后每个人都很高兴,小精灵可以再次围着篝火跳舞

if (this.hasClass("toggler")) { return; }    //Your Code, wrong.
if ($(this).hasClass("toggler")) { return; } //My Code, right.
试试这个

$("input[type=checkbox]").each(function(index) {
  if($(this).attr('class')=='toggler')
    alert ('yes class is there');
  else
    alert ('no class is not there');
});

试试这个

$("input[type=checkbox]").each(function(index) {
  if($(this).attr('class')=='toggler')
    alert ('yes class is there');
  else
    alert ('no class is not there');
});


您也可以使用


您也可以使用


我不明白,如果你需要“检查是否是复选框”,那么上面的“this.checked”行如果不是如何工作?我不明白,如果你需要“检查是否是复选框”,那么上面的“this.checked”行如果不是如何工作?