hasClass(class)

2018-02-24 15:14 更新

返回值:BooleanhasClass(class)

概述

檢查當(dāng)前的元素是否含有某個(gè)特定的類,如果有,則返回true。

這其實(shí)就是 is("." + class)。

參數(shù)

classStringV1.2

用于匹配的類名

示例

描述:

給包含有某個(gè)類的元素進(jìn)行一個(gè)動(dòng)畫(huà)。

HTML 代碼:
<div class="protected"></div><div></div>
jQuery 代碼:
$("div").click(function(){
  if ( $(this).hasClass("protected") )
    $(this)
      .animate({ left: -10 })
      .animate({ left: 10 })
      .animate({ left: -10 })
      .animate({ left: 10 })
      .animate({ left: 0 });
});
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)