0

我有这个:

<div id="taglist">
    <input type="checkbox" name="chkB1" id="chkB1" value="Mon" />&nbsp;Monday&nbsp;&nbsp;
    <input type="checkbox" name="chkB2" id="chkB2" value="Tue" />&nbsp;Tuesday&nbsp;&nbsp;
    <input type="checkbox" name="chkB3" id="chkB3" value="Wed" />&nbsp;Wednesday&nbsp;&nbsp;
    <input type="checkbox" name="chkB4" id="chkB4" value="Thu" />&nbsp;Thursday&nbsp;&nbsp;<br />
    <input type="checkbox" name="chkB5" id="chkB5" value="Fri" />&nbsp;Friday&nbsp;&nbsp;
    <input type="checkbox" name="chkB6" id="chkB6" value="Sat" />&nbsp;Saturday&nbsp;&nbsp;
    <input type="checkbox" name="chkB7" id="chkB7" value="Sun" />&nbsp;Sunday&nbsp;&nbsp;
    <input type="hidden" name="source_frequency" id="source_frequency" value="" />
</div>

还有这个:

var days = ["Mon","Tue","Wed","Sun"];

我希望天数中的值选中相应的复选框。怎么会做这样的事情:-)

4

4 回答 4

5
var days = ["Mon","Tue","Wed","Sun"];

for(var day in days){
  $('#taglist input[value='+days[day]+']').prop("checked", true);
}
​
于 2012-06-03T04:24:51.590 回答
0
    var days = "Mon","Tue","Wed","Sun";
    var array=days.split(',');
    $(':checkbox').each(function(){
    if($.inArray($(this).val(), array)>=0)
    {
       $(this).attr('checked');
    }
    });
于 2012-06-03T04:27:53.120 回答
0

就像在你的可变日子里有一个循环一样

    $(document).ready(function(){
        var days = ["Mon","Tue","Wed","Sun"]; //days array 
        for(var i=0;i<=days.length;i++){
           $('#taglist input[value='+days[i]+']').prop("checked", true);
        }
    });
于 2012-06-03T04:29:51.117 回答
0
var days = ["Mon","Tue","Wed","Sun"];

$(':checkbox[name^=chkB]').filter(function(index, val) {
    if(days.indexOf(this.value) >= 0)
        return this.checked = true;
});

样品锻炼

于 2012-06-03T04:33:58.710 回答