JQ 动态加载多选框--随记

=====================html 

<table>

<tr>
<td style="Width: 100px; text-align: right;"><span class="sp">借款产品:</span></td>

<td id="checlboxlist">
 

</td>

</tr>

</table>

===============================jq代码
function initLoaneeProduct()
{
$.ajax({
type : "post",
url : "./externalSources/XXXX/XXX.gxtweb",
//data : {},
success : function(result) {
var listHtml="";

for(var i = 0;i<result.length;i++){
// alert(result[i].id+","+result[i].name);
listHtml += " <span class='spbox'><input type='checkbox'";
listHtml += "name='category'";
listHtml += " id=cr0"+i;
listHtml += " value="+result[i].id;
listHtml += " style=border:none;/>";
listHtml += ""+result[i].name;
listHtml += "</span>";
}

$("#checlboxlist").html(listHtml).css("text-align","left");
}

});
}

========================================================设定选中状态

function  funs()

{

alert(result[i].LOAN_PRODUCT_LIST); //借款产品
var mycars=new Array();
mycars=result[i].LOAN_PRODUCT_LIST.split(",");
for(var k=0;k<mycars.length;k++)
{

var items = document.getElementsByName("category");
for (i = 0; i < items.length; i++) {

if (items[i].value==mycars[k]) {

items[i].checked=true;
}
}
}

}

 

posted @ 2016-08-17 09:43  秋香姑娘请你不要紧张  阅读(439)  评论(0编辑  收藏  举报