gpt4 book ai didi

javascript - 根据数组中的值检查复选框

转载 作者:搜寻专家 更新时间:2023-11-01 05:12:38 25 4
gpt4 key购买 nike

复选框检查数组或值

HTML 代码:

<div id="weekdays">
<label for="saturday"> Saturday </label><input type='checkbox' name='week_day[]' value='saturday' id="saturday">
<label for="sunday"> Sunday </label><input type='checkbox' name='week_day[]' value='sunday' id="sunday">
<label for="monday"> Monday </label><input type='checkbox' name='week_day[]' value='monday' id="monday">
<label for="tuesday"> Tuesday </label><input type='checkbox' name='week_day[]' value='tuesday' id="tuesday">
<label for="wednesday"> Wednesday </label><input type='checkbox' name='week_day[]' value='wednesday' id="wednesday">
<label for="thursday"> Thursday </label><input type='checkbox' name='week_day[]' value='thursday' id="thursday">
<label for="friday"> Friday </label><input type='checkbox' name='week_day[]' value='friday' id="friday">

数组

var f = ["saturday", "sunday", "monday"] 

信息我想在此表格上查看星期六、星期日和星期一的日期

最佳答案

jQuery 选择器只是一个字符串,所以只需将数组连接到一个 ID 字符串中即可:

$('#'+f.join(', #')).prop('checked', true);

FIDDLE

关于javascript - 根据数组中的值检查复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17537579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com