eq(index)
获取第N个元素
这个元素的位置是从0算起。
Reduce the set of matched elements to a single element.
The position of the element in the set of matched elements starts at 0 and goes to length – 1.
返回值
jQuery
参数
index (Integer) :元素在jQuery对象中的索引
示例
获取匹配的第二个元素
HTML 代码:
<p> This is just a test.</p> <p> So is this</p>
jQuery 代码:
$(“p”).eq(1)
结果:
[ <p> So is this</p> ]
————————————————————————————————————–
hasClass(class)
检查当前的元素是否含有某个特定的类,如果有,则返回true。
这其实就是 is(“.” + class)。
Checks the current selection against a class and returns true, if at least one element of the selection has the given class.
This is an alternative to is(“.” + class).
返回值
Boolean
参数
class (String) : 用于匹配的类名
示例
给包含有某个类的元素进行一个动画。
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 });
});
————————————————————————————————————–
filter(expr)
筛选出与指定表达式匹配的元素集合。
这个方法用于缩小匹配的范围。用逗号分隔多个表达式
Removes all elements from the set of matched elements that do not match the specified expression(s).
This method is used to narrow down the results of a search. Provide a comma-separated list of expressions to apply multiple filters at once.
返回值
jQuery
参数
expr










