- 0133技术站
- 联系QQ:18840023
- QQ交流群

- 微信公众号

jQuery is() 方法
定义和使用
is() 方法用于查看选择的元素是否匹配选择器。
语法
$(selector).is(selectorElement,function(index,element))
参数 | 描述 |
selectorElement | 必须。选择器表达式,根据选择器/元素/jQuery 对象检查匹配元素集合,如果存在至少一个匹配元素,则返回 true,否则返回 false |
function(index,element) | 可选。指定了选择元素组要执行的函数
|
<script> $(document).ready(function(){ $("p").click(function(){ if ($("p").parent().is("div")) { alert("p 的父元素是 div"); } }); }); </script> </head> <body> <div> <p>点我查看父元素是否是 div。</p> </div>
点击 "运行实例" 按钮查看在线实例
效果图:
推荐手册