1. 程式人生 > >easyui ajax 動態生成CheckBox 複選框

easyui ajax 動態生成CheckBox 複選框


json

[

{"ID":1,"value":"首頁"},

{"ID":2,"value":"滾動"},

{"ID":3,"value":"公告"}

]

function CreateAjaxCheckBox(Obj,strParaList,url)

{
 $.post(url, function (data) {
 var response = eval("(" + data + ")"); //轉換為json物件   
 var listHtml=''; 
$.each(response,function(i){ 
  
    if(response[i].value!="")
    {
  
    listHtml += " <input type='checkbox' "+(strParaList!=""?(strParaList.indexOf(","+response[i].Id+",") >= 0?"checked='checked'":""):"")+" name='"+Obj+"' id='"+Obj+response[i].Id+"' value='"+response[i].Id+"'>"+response[i].value; 
    } 
    
    }); 
    
    $("#"+Obj).html(listHtml);
 
});
        


}

獲取值
function GetCheckBoxList(Obj)
{


 var s="";
 var r=document.getElementsByName(Obj);  
 for(var i=0;i<r.length;i++){
         if(r[i].checked){
           s+=r[i].value+",";
       }
}   
return (s!=''?(','+s+',').replace(',,',','):'').replace(',,',',');


}