返回值:Boolean hasClass(class)
概述
檢查目前的元素是否含有某個特定的類,如果有,則返回true。
這其實就是 is("." + class)。
參數
class String V1.2
用於匹配的類名
示例
描述:
給包含有某個類的元素進行一個動畫。
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 });
});