传字符串js多选框选中

<dl class="nowrap">
			<dt>可操作店铺:</dt>
			<dd><div id="ushops" val="${shops}"></div></dd>
</dl>

 注:action里面的值是private String shops;

shops通过数据库查询得到的结果是shops=“1,5,6,7,9”

页面需要的个人所操作店铺多选框进行选中,js解析方法案例如下

 

<script language="JavaScript">
<!--
$(document).ready(function() {
	$.getJSON("getShops.do", function(data){
			var html = '';
			var shops = $("#ushops").attr('val');
		$.each(data, function(i,item){
			
			if(shops.indexOf(''+item.id)>-1)
			 	html += '<label><input type="checkbox" name="shops" value="' + item.id + '" checked>' + item.shopName + '</label>';
			 else
			 	html += '<label><input type="checkbox" name="shops" value="' + item.id + '" >' + item.shopName + '</label>';
			 	
			 
		});
		$("#ushops").append(html);
	});
});
//-->
</script>

 

你可能感兴趣的:(字符串)