JSP、 <div id="info" data-bind="foreach:itemsA"> <button name="userBtn" style="width:155px;height:30px;margin-left:8px;margin-top:5px" data-bind="style:{backgroundColor:$data.count>0?'#00c1de':''},attr: {count:$data.count},data:$data,click:$root.assignUser,value:userId,text:userName"></button> </div>
JS、 function setChecked(){ var $boxes = $("button[name='userBtn']"); for(var i=0;i<$boxes.length;i++){ var id = $boxes[i].value; if(checkedIds.indexOf(id,0)!=-1||$boxes[i].attributes.count.value>0){ $boxes[i].style.backgroundColor = "#00c1de"; }else{ $boxes[i].style.backgroundColor = ""; } } }