jquery遍历数组
来源:互联网 发布:java打印上下杨辉三角 编辑:程序博客网 时间:2024/05/22 01:42
1.用$(arrays).each(function(index,element){ })
的方式
index是可选参数表示是数组中的第几个元素;
element是当前遍历到的元素;
//获取每一列的表头信息
var tabhead = $("#cpggtable .producthead")$(tabhead).each(function(i,n){ //ok var name = $(this).attr("name"); //alert(name); if(name=="isValidity"){ tableRow.insertCell(i).innerHTML = "是<input class='productisValidity' type = 'radio' name="+k+" value='true' checked='checked'/> 否<input class='productisValidity' type = 'radio' name="+k+" value='false'/>"; k++; }else if(name=="descript"){ tableRow.insertCell(i).innerHTML= "<textarea class='producvalue producw' name='producvalue'></textarea>"; }else if(name =="productValid"){ tableRow.insertCell(i).innerHTML= "<input class='producvalue' type = 'text' name='producvalue' onkeyup=this.value=this.value.replace(/[^0-9.]/g,'') onafterpaste=this.value=this.value.replace(/[^0-9.]/g,'')/>"; }else if(name == "productprice"){ tableRow.insertCell(i).innerHTML= "<input class='producvalue' type = 'text' name='producvalue'/>"; } else if(name == "productField1"){ tableRow.insertCell(i).innerHTML="<input class='producvalue' type = 'text' name='productField1' onkeyup=this.value=this.value.replace(/[^0-9.]/g,'') onafterpaste=this.value=this.value.replace(/[^0-9.]/g,'')/>"; } })
2.用数组下标的方式进行添加
//获取每一列的表头信息
var tabhead = $("#cpggtable .producthead"); for(var j = 0;j<tabhead.length;j++){ var name2 = $(tabhead[j]).attr("name"); alert(name2); }
3.$.each(xxx, function() {})遍历一个解析好的对象
var productSpecj = eval('$!productSpecJsons'); if(typeof(productSpecj)=="undefined" || productSpecj=="") return; var productSpecRows = $("#cpggtable").find('tr[class="productspecrow"]'); var productSpecId = $(op).find("option:selected").attr("id"); $.each(productSpecj, function() { if(this.id==productSpecId){ var productSecDesc = this.descript; var productPrice = this.price; var productValid = this.productValid $("#cpggtable").find('li[id="productDes"]').html("产品描述:"+productSecDesc); $("#cpggtable").find('li[id="productValid"]').html("产品期限:"+productValid+"年"); $("#cpggtable").find('span[id="productprice"]').val(productPrice.toFixed(2)); $("#cpggtable").find('span[id="productprice"]').html("¥"+productPrice); }; });
错误的不可行方式://获取每一列的表头信息 var tabhead = $("#cpggtable .producthead"); for(var j = 0;j<tabhead.length;j++){ //buxing //$(tabhead).get[j].attr("name"); //buxing //var input = tabhead.get[j]; //alert(input); //var name = $(input).attr("name"); }
0 0
- jquery 遍历json数组
- jquery 数组遍历
- jQuery遍历json数组
- JQuery遍历数组
- jQuery 遍历数组
- jquery遍历数组
- JQuery 数组遍历方法
- jquery遍历json数组
- Jquery 遍历json和数组
- jquery 遍历对象、数组、集合
- jquery 遍历对象、数组、集合
- jquery遍历json数组方法
- jQuery遍历对象/数组/集合
- jquery遍历json数组方法
- jquery遍历对象、数组、集合
- jquery 遍历对象、数组、集合
- jquery 遍历对象、数组、集合
- jquery 遍历对象、数组、集合
- linux内核接口——Linux二进制兼容性问题
- datatable绑定comboBox显示数据[C#]
- ios蓝牙使用demo
- java下main,dao,model,service,impl,util包名含义
- Freemark的使用总结
- jquery遍历数组
- spark中的RDD算子
- EasyMock
- MyBatis的动态SQL详解
- Ios xcode8构建之后,validate,和update appstore为灰色解决办法
- 使用ping命令进行连通性校验的shell脚本
- 最近学习
- caffe的Matlab接口的使用方法
- 输入输出系统的发展和组成