前端之家收集整理的这篇文章主要介绍了
ajax动态加载下拉框、单选框、复选框,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//select下拉
菜单动态加载 方式一: $.ajax({ type:"get",dataType:"json",contentType:"application/json;charset=utf-8",url:"url",success:function(result){ $.each(result,function(index,value){ $("#id").append("<option value='"+value.yxdm+"'>"+value.yxmc>+"</option>"); }) },error : function(XMLHttpRequest,textStatus,errorThrown) { alert(errorThrown); },async:false //false表示同步 }); 方式二: $.ajax({ type:"get",function(i,n){ $("#id")[0].options.add(new Option(n.xykmmc,n.yxkmbh)); }); $("#id").get[0].selectedIndex = 0; },async:false //false表示同步 }); //ra
dio单选框动态加载 function getAjax(get_url){ $.ajax({ type:"get",success:function(result1){ result = result1; },error:function(XMLHttpRequest,errorThrown){ alert(errorThrown); },async:false }); return result; } var url_bkzy = server_path + "/rest/zy/zzzs/"+y2; var getBkzy = getAjax(url_bkzy); //
获取JSON数据 var value = ""; for(var i = 0; i<getBkzy.length; i++){ if(i==0){ if(getBkzy[i].zyfxmc!=""&&getBkzy[i].zyfxmc!=null){ value = value + "<input type='ra
dio' name='ra
dio3' value='"+getBkzy[i].xtzyh+"' checked/>"+getBkzy[i].zymc+"("+getBkzy[i].zyfxmc+")"; }else{ value = value +"<input type='ra
dion' name='ra
dion3' value='"+getBkzy[i].xtzyh+"' checked/>"+getBkzy[i].zymc; } }else{ if(getBkzy[i].zyfxmc !="" && getBkzy[i].zyfxmc != null){ value = value + " <input type='ra
dio' name='ra
dio3' value='"+getBkzy[i].xtzyh+"'/>"+ getBkzy[i].zymc +"("+ getBkzy[i].zyfxmc + ")" ; }else{ value = value + " <input type='ra
dio' name='ra
dio3' value='"+getBkzy[i].xtzyh+"'/>"+ getBkzy[i].zymc ; } } $("#tjzy").html(value); } //check
Box动态加载 function loadYhzList(yhzSel,yhzurltemp){ $.ajax({ type:"get",url : yhzurltemp,success:function(result){ $.each(result,value){ yhzSel.append("<input id='yhzlist"+index+"' type='check
Box' value='"+ value.zbh +"'/><label for='check
Box"+index+"'>"+value.zjj+"</label> "); }); },error:function(result){ },async:false }); }