合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
eq(index|-index):jQuery get(index):HTML ~~~ $("img").get(0);//<img src="test1.jpg"/> //html <img src="test1.jpg"/> <img src="test2.jpg"/> ~~~ first() 获取匹配的第一个元素 last() 获取匹配的最后一个元素 hasClass(class) 检查当前的元素是否含有某个特定的类,如果有,则返回true。这其实就是 is("." + class)。 ~~~ if ( $(this).hasClass("protected") ){} ~~~ filter(expr|obj|ele|fn) 筛选出与指定表达式匹配的元素集合。 这个方法用于缩小匹配的范围。用逗号分隔多个表达式 ~~~ //保留带有select类的元素 $("p").filter(".selected") //保留第一个以及带有select类的元素 $("p").filter(".selected, :first") //保留子元素中不含有ol的元素。 $("p").filter(function(index) { return $("ol", this).length == 0; }); ~~~ is(expr|obj|ele|fn) 根据选择器、DOM元素或 jQuery 对象来检测匹配元素集合,如果其中至少有一个元素符合这个给定的表达式就返回true。 ~~~ //检查input元素的父元素是一个表单元素 $("input[type='checkbox']").parent().is("form") ~~~ * [map(callback)](https://jquery.cuishifeng.cn/map.html) * [has(expr|ele)](https://jquery.cuishifeng.cn/has.html "has(expr|element)") * [not(expr|ele|fn)](https://jquery.cuishifeng.cn/not.html "not(expr|element|fn)") * [slice(start,\[end\])](https://jquery.cuishifeng.cn/slice.html "slice(start,[end])")