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