遍历匹配元素,获得元素对象和指定属性值
xiyueta().item()属性方法,两种调用方式:
1、xiyueta("div").item(); //获得每个匹配的元素,同jquery的.each类似
2、xiyueta("div").item("id"); //获得每个匹配的元素对应标记参数值,放到value属性里
总结:
xiyueta().item()这个属性方法类似jQuery的.each()方法,在ASP程序里不可以用$().each(function(){})这种方法。
为了可以在ASP程序里可以使用遍历元素对象属性方法,所以xiyueta.js库里加入了$().item()方法,同时$().item()属性方法还可以带一个指定元素属性名,会以val属性追加到数组对象里。如{x:1,y:3,val:'1.jpg'}
尝试一下>>
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script> <script>
var html='<div>\n\ <a href="default.html">首页</a>\n\ <a href="news.html">新闻</a>\n\ <a href="products.html">产品</a>\n\ </div>'; $().parse(html); $.log($("a").item()); document.write("<br>"); $.log($("a").item("href")); document.write("<br>"); var arr=$("*").item("href"); for(var i=0;i<arr.length;i++){ $.log(i,arr[i].value); document.write("<br>"); }
</script>
index: 0 , x: 1 , y: 2 , value: <a href="default.html">首页</a> , 0
index: 1 , x: 3 , y: 4 , value: <a href="news.html">新闻</a> , 1
index: 2 , x: 5 , y: 6 , value: <a href="products.html">产品</a> , 2
index: 0 , x: 1 , y: 2 , value: default.html , 0
index: 1 , x: 3 , y: 4 , value: news.html , 1
index: 2 , x: 5 , y: 6 , value: products.html , 2
0default.html
1news.html
2products.html