Jquery的filter,not,find和JS中的split,join

来源:互联网 发布:mac口红专柜多少钱一支 编辑:程序博客网 时间:2024/05/01 06:15

基本是find子元素找,filter是平级找

·find 函数是在当前对象集合的子元素中进行查询;
·filter 函数是对当前对象集合进行过滤, 利用过滤条件缩小范围;

<script type="text/javascript"> $(document).ready(function() { //输出 hello alert($("p").filter(".selected").html()); //输出 How are you? alert($("p").not(".selected").html()); }); </script> </head> <p class="selected">Hello</p><p>How are you?</p> </body> 

从一组类似或相同的元素中只选择某一个特定的元素。 
jQuery提供了filter()和not()来做这个。 
filter()能够将元素精简到只剩下满足过滤条件的那些,not()恰恰相反,他移除了所有满足条件的。


而split,和join是用来处理字符串的,

$(function(){var zifu="nihao1hello1nihao1heihei1mmm";var xin=[];$.each(zifu.split("1"),function (key,val) {console.log(key+"---"+val);xin[key]=val;});console.dir(xin);        var yun=xin.join("");        console.info(yun);        console.info(zifu.split("1").join("+"));});


0 0
原创粉丝点击