📜  jQuery的hasClass()

📅  最后修改于: 2020-11-26 01:19:16             🧑  作者: Mango

jQuery hasClass()

jQuery的hasClass()方法用于检查所选元素是否具有指定的类名。如果指定的类存在于任何选定的元素中,则返回TRUE,否则返回FALSE。

句法:

$(selector).hasClass(classname) 

jQuery hasClass()方法的参数

Parameter Description
className It is a mandatory parameter. It specifies the name of the CSS class to search for in the selected elements.

jQuery hasClass()方法的示例

让我们以一个示例来演示jQuery hasClass()方法。






jQuery hasClass()方法示例2

让我们再举一个例子来演示jQuery hasClass()方法。




The Selecter Example





This is first paragraph.

This is second paragraph.

在这里,第一个条件为true,第二个条件为false。如果我们设置第二段的类名是“ blue”?那么这两个条件都将成立。

jQuery hasClass()示例3




The Selecter Example





This is first paragraph.

This is second paragraph.

这两个条件都将成立。

jQuery hasClass()示例4



  
  
     
  
 
 
 

jQuery .hasClass() function Example

  • Red
  • Green
  • Green Red
  • Blue