jQuery

利用filter函数能够从wrapper set中过滤符合条件的DOM元素。

假设我们有一个内容例如以下的html文件,要获取类为external的<a>元素,使用filter能够非常easy地搞定。


filter的參数类型可分为两种:

1 传递选择器

2 传递过滤函数


假设使用选择器作为參数,使用方法例如以下

$('a').filter('.external')

使用匿名过滤函数

$('a').filter(function(index) {
		return $(this).hasClass('external');
	})

參数index是结果集的下标.

Related Posts

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注