文字
分享

返回值:BooleanhasClass(class)

概述

检查当前的元素是否含有某个特定的类,如果有,则返回true。

这其实就是 is("." + class)。

参数

classStringV1.2

用于匹配的类名

示例

描述:

给包含有某个类的元素进行一个动画。

HTML 代码:

1

<code><div class="protected"></div><div></div></code>

jQuery 代码:

1

2

3

4

5

6

7

8

9

<code>$("div").click(function(){

  if ( $(this).hasClass("protected") )

    $(this)

      .animate({ left: -10 })

      .animate({ left: 10 })

      .animate({ left: -10 })

      .animate({ left: 10 })

      .animate({ left: 0 });

});</code>

上一篇:last()下一篇:filter(expr|obj|ele|fn)