gpt4 book ai didi

javascript - JQuery 不从复选框列表返回值,返回状态

转载 作者:行者123 更新时间:2023-11-28 08:51:36 25 4
gpt4 key购买 nike

请让我知道我可以在这里纠正什么,我被锁定在一些看似简单的事情上。

使用 JQuery 1.6.2:

我正在尝试返回 CheckBoxList 中已选中项目的值数组。

使用来自网络的修改示例,我有以下内容,它返回一个“on、on、on、on”数组(如果选中所有 4 个复选框)。

Shots.push($(this).prop('checked')) 返回“true, true...”Shots.push($(this).attr('Value')) 返回“on, on...”

            var Shots = [];

$('#cblShots').find('input[type=checkbox]:checked').each(function () {
Shots.push($(this).val());
});

if (Shots != "") {
$(Pnote).val(Shots.join(', '));
} else {
updateTips("Please select at least one item");
return false;
}


<asp:Panel ID="pnlAppointmentShotSelection" runat="server" style="display:none;">
<label>Please select which shots you would like administered</label>
<br /><br />
<asp:CheckBoxList ID="cblShots" runat="server" CssClass="ShotList">
<asp:ListItem Value="Flu">Flu</asp:ListItem>
<asp:ListItem Value="B-12">B-12</asp:ListItem>
<asp:ListItem Value="Pneumonia">Pneumonia</asp:ListItem>
<asp:ListItem Value="TDAP">Tetanus-Diptheria-Pertusis (TDAP)</asp:ListItem>
</asp:CheckBoxList>
</asp:Panel>

最佳答案

根据这个post可以将数据属性添加到 ListItem,因此请尝试向每个元素添加数据名称属性,然后在 javascript 中尝试此操作:

var Shots = [];
$('#cblShots').find('input[type=checkbox]:checked').each(function () {
Shots.push($(this).attr("data-name"));
});

关于javascript - JQuery 不从复选框列表返回值,返回状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19080434/

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