核心提示:jQuery:jsp页面获取子节点的值,添加字符串到字符数组,判断checkbox是否被选中直接上代码 var origAttr=[];function getOrigAttr(temp){var o...
jQuery:jsp页面获取子节点的值,添加字符串到字符数组,判断checkbox是否被选中
直接上代码var origAttr=[]; function getOrigAttr(temp){ var orig = $(temp); var origStr = []; if(orig.length > 0){ for (var i =0 ; i < orig.length ;i++){ //将字符串添加到字符数组 origStr.push(orig.eq(i).val()); } } return origStr; } var temp = $("#Property_c").find('input:checkbox[name=373]:checked');//获取子节点的值:find origAttr = getOrigAttr(temp);//调用getOrigAttr函数 if(origAttr.length>0){ var checked = $("input:checkbox[name=373]").is(':checked');//判断checkbox是否被选中 if(checked == true){ //遍历checkbox选中的值 $("#"+id+" input:checkbox[name=373]:checked").each(function(index){ str += "\""+$(this).attr("id")+"__"+index+"\":\""; str += $(this).val()+"\","; }); }else{ for(var i =0 ; i < origAttr.length ; i++ ){ var m= 0; if(origAttr[i] == "IP_adminPort"){ m=0; }else if (origAttr[i] == "IP_static"){ m=1; }else if (origAttr[i] == "IP_dynamic"){ m=2; }else{ m=3; } str += "\""+"373__"+m+"\":\""; str += ""+"\","; } } }