jQuery API | jQuery API 中英文对照版 - jQuery在线查询手册 |
is(expr) |
is(expr)
用一个表达式来检查当前选择的元素集合,如果其中至少有一个元素符合这个给定的表达式就返回true。 返回值:Boolean 参数:
因为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
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 |