function getLands() {

         $.ajax({
url:"httpserver.do?doPost&userQygs="+$("#userQygs").val(),
type:"POST",
dataType:"text", success:function(data){ if(data==null||data==""){ alert("目前没有地块可供选择,请先绘制地块!");
location.href ="gpadd.do?toArcgis&state=1";
}else{ var lands=data.split(","); //获得前台的div
var insertDiv = document.getElementById("land");
//定义向前台插入的内容为空
insertDiv.innerHTML = "";
var chkinfo;
var chkDIV;
//var txtinfo;
//解析从服务器获得的数据,循环添加复选框
for (var i = 0; i < lands.length-1; i++) {
//为每一个复选框创建一个DIV
chkDIV = document.createElement("div");
//每一个复选框用input创建,类型为checkBox
chkinfo = document.createElement("input");
chkinfo.name = "landDkbh";
chkinfo.id = "landDkbh";
chkinfo.type = "checkbox";
// chkinfo.onclick = test;
//将每一个chinesename为复选框赋值
chkinfo.value = lands[i];
//将复选框添加到Div中
chkDIV.appendChild(chkinfo);
//为Div设置样式
chkDIV.style.height = "50px";
chkDIV.style.width = "150px";
chkDIV.style.float = "left";
chkDIV.align = "left";
chkDIV.appendChild(document.createTextNode(lands[i]));
//将创建的div添加到前台预留的DIV下
insertDiv.appendChild(chkDIV);
} //第二种方法,用拼接的方法来完成,比较简单
/* for(var i=0;i<data.length;i++){ $("#land").append("<tr> <td> <input type='checkbox' name='landDkbh' id='landDkbh' value="+data[i].landDkbh+" /></td> <td>"+data[i].landName+"</td><td>"+data[i].landScmj+"</td> <th><a href='javascript:void(0)' onclick=\"look('"+data[i].landDkbh+"')\" >查看</a></th></tr>"); } */ }
}
}); }
 

添加复选框的位置

  <div class="col-sm-5">
<div class="form-group">
<label class="col-sm-3 control-label">选择地块</label>
<div class="col-sm-9" > <div id="land" > </div> </div>
</div>
</div>
04-25 09:17