0
var ds = $("#recDay").val().split(/ +/); 
var weekArray = [];
for (var i=0; i<ds.length; i++){
    weekArray = ds[i];
} // i =0 , weekArray = Sunday; i=1, weekArray = tuesday; i=2, weekArray = Wednesday

<table>
<tr>
<td width="3%"></td>
<td><input type="checkbox" name="weeklyDay" id="sunday" value="sunday"> Sunday</td>      
<td><input type="checkbox" name="Day" id="monday" value="monday"> Monday</td>                                                                               
<td><input type="checkbox" name="Day" id="tuesday" value="tuesday"> Tuesday</td>                                                                                
<td><input type="checkbox" name="Day" id="wednesday" value="wednesday">Wednesday</td>                                                                              
</tr>                                                                            
<tr>                                                                                
<td width="3%"></td>                                                                                
<td><input type="checkbox" name="Day" id="thursday" value="thursday" > Thursday</td>                                                                                   
<td><input type="checkbox" name="Day" id="friday" value="friday"> Friday</td>                                                                                 
<td><input type="checkbox" name="Day" id="saturday" value="saturday"> Saturday</td>                                                                         
</tr>                                                                       
</table>

如何仅选中 weekArray 中的复选框?我试过的代码是

$('select[name="Day"] option').filter(function(){
         if(weekArray.indexOf((this).text(), 0) != -1);
         return $(this);
    }).prop("checked", true);

但这不起作用。任何帮助,将不胜感激

4

4 回答 4

1

您正在使用select选择器checkbox ??????..

 $('#divID input:checkbox').each(function(){
     if($.inArray($(this).val(), weekArray) != -1){
       $(this).prop("checked", true);
    }
});
于 2013-03-13T07:09:10.367 回答
1

你可以这样做,

现场演示

var weekArray = ["saturday","monday","tuesday","friday" ];
$('.weekdays').filter(function () {    
    if (weekArray.indexOf(this.id) != -1)
          return $(this).closest('td').find(':checkbox');
}).prop("checked", true);
于 2013-03-13T07:13:06.650 回答
0
for (var i=0; i<ds.length; i++){
    weekArray = ds[i];
}

$("form input:checkbox").each(function(){
if(jQuery.inArray($(this).attr('id'), weekArray )!=-1)
$(this).prop('checked', true);
});
于 2013-03-13T07:09:42.110 回答
0
if(in_array(document.getElementById("CheckBoxId"), $yourArray)) { CheckBox.Checked }
于 2013-03-13T07:07:15.050 回答