一些关于 checkbox的前台 jquery 操作 记录

$(function() { //页面载入函数
var partList = jQuery.parseJSON( '${KeyWordsList}');
$.each(partList,function(key,value){
//console.log(key);
// console.log(value['ID']+' '+value['KeyWord']);
if(value['ID']%3 == 0){
//<label><input name="Fruit" type="checkbox" value="" />苹果 </label>
$('#keywords_tab_one').append("<td style='text-overflow:ellipsis;word-break:keep-all; white-space:nowrap;'><label><input name='KeyWords' value='"+value['KeyWord']+"' type='checkbox'/>"+value['KeyWord']+"</label></td>");
}

if(value['ID']%3 == 1){
$('#keywords_tab_two').append("<td><label><input name='KeyWords' value='"+value['KeyWord']+"' type='checkbox'/>"+value['KeyWord']+"</label></td>");
}

if(value['ID']%3 == 2){
$('#keywords_tab_three').append("<td><label><input name='KeyWords' value='"+value['KeyWord']+"' type='checkbox'/>"+value['KeyWord']+"</label></td>");
}
});

var selectedkeyList ="${plantdefdetailCSA.KeyWords}";
var selectedwords=selectedkeyList.split(",");

$("#keywords_tab input[name=KeyWords]").each(function(){ //遍历table里的全部checkbox
console.log('check'+$(this).val());
for(var i=0;i<selectedwords.length;i++){
if($(this).val()==selectedwords[i]){
$(this).attr("checked","checked");
console.log('nice!');
}
}


});





var width=$('#keywords_tab').width();
console.log('width='+width);
if(width<350){
$('.td_keywords_tab').css('overflow-x','visible');
}else{
$('.td_keywords_tab').css('overflow-x','scroll');
}


});

原文地址:https://www.cnblogs.com/jiangyi666/p/6137013.html