JQuery遍历
两种遍历方式:
jquery对象.each(function(index,ele){
//this 遍历后的结果 js对象
//ele 遍历后的结果 js对象
//index 索引
})
$.each(jquery对象,function(index,ele){
//this 遍历后的结果 js对象
//ele 遍历后的结果 js对象
//index 索引
})
案例:遍历隐藏域的值
直接上代码:
05-可见性过滤选择器.html
$(function() {
$("#b1").click(function() {
/*
* 方式一:
*
* $("[type=hidden]").each(function() {
alert(this.value);
});
*
* */
//方式二:
$("[type=hidden]").each(function(index, val) {
alert(index + " : " + val.value);
});
})
$("#b2").click(function() {
$.each($("[type=hidden]"), function(index, val) {
alert(index + " : " + val.value);
});
})
});