遍历匹配元素,为每个匹配元素规定运行的函数,返回false为停止循环
xiyuetaCSS().each()属性方法,一种调用方式:
1、xiyuetaCSS("div").each(); //遍历匹配元素,为每个匹配元素规定运行的函数,返回false为停止循环
总结:循环出来的对象,jQuery里是浏览器里的原生对象,而xiyueta里是一个数组,两者有一定区别,jQuery里可直接调用浏览器里原生API,如this.innerHTML来获得html内容,而xiyueta里不可以,因为xiyueta里只提取元素在数组里的索引位置,除了不能调用浏览器里html原生api,其它部分则一样使用,如$(this).text()。
xiyuetaCSS().each()用法与jQuery中jQuery().each()用法保持一致
see https://api.jquery.com/each
尝试一下>>
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script> <script>
xiyuetaCSS().parse("a{color:red}b{color:blue}p{color:green}"); xiyuetaCSS("(all)").each(function(i,obj){ $.log(i+"、", xiyuetaCSS(this).css("color")); document.write("<br>") })
</script>
0、red
1、blue
2、green