jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
is(expr)
is(expr)

用一个表达式来检查当前选择的元素集合,如果其中至少有一个元素符合这个给定的表达式就返回true。

如果没有元素符合这个表达式,或者表达式是无效的,都返回false。

其中的表达式可以使用filter(String)函数,因此filter()函数原有的规则在这里也适用。

返回值:Boolean

参数:

  • expr (String): 用于筛选的表达式
 
示例:

因为input元素的父元素是一个表单元素,所以返回true。

$("input[@type='checkbox']").parent().is("form") 

HTML 代码:

<form><input type="checkbox"   /></form>

结果:

true
示例:

因为input元素的父元素是一个p元素,所以返回false。

$("input[@type='checkbox']").parent().is("form") 

HTML 代码:

<form><p><input type="checkbox"   /></p></form>

结果:

false
 

is( expr )

Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.

Does return false, if no element fits or the expression is not valid.

filter(String) is used internally, therefore all rules that apply there apply here, too.

Return value: Boolean
Parameters:

  • expr (String): The expression with which to filter
 

Example:

Returns true, because the parent of the input is a form element

 $("input[@type='checkbox']").parent().is("form")  
Before:
 <form><input type="checkbox" /></form>  
Result:
 true  

Example:

Returns false, because the parent of the input is a p element

 $("input[@type='checkbox']").parent().is("form")  

Before:

 <form><p><input type="checkbox" /></p></form>  
Result:
 false