我知道我的回应很晚,但它可以帮助你。你的数组可能会喜欢这个{“foo1”:“india”,“foo2”:“阿富汗”,“foo3”:“阿尔巴尼亚”};
$(document).ready(function(){
var myid,myvalue;
var object={"foo1":"india","foo2":"Afghanistan","foo3":"Albania"};
jQuery("input[name='country']").each(function() {
myid=this.id;
myvalue=this.value;
$.each(object,function(key,value)
{
if(value==myvalue)
{
$("#"+myid).attr("checked",true);
}
});
});
});
在HTML
<body>
<form>
<input type="checkbox" id="foo1" name="country" value="india">india
<input type="checkbox" id="foo2" name="country" value="Afghanistan">Afghanistan
<input type="checkbox" id="foo3" name="country" value="Albania">Albania
<input type="checkbox" id="foo4" name="country" value="Algeria">Algeria
</form>
</body>
</html>
请检查的jsfiddle在http://jsfiddle.net/s3sLhbdn/ – TechMech
作品在我的iPhone:http://fiddle.jshell.net/s3sLhbdn/show/光/ – mplungjan