gpt4 book ai didi

javascript - ASP JavaScript - CheckBoxList - 将选定值捕获到 Label.Text

转载 作者:行者123 更新时间:2023-12-03 05:32:14 25 4
gpt4 key购买 nike

我需要一些帮助。下面有一个复选框列表。

<asp:Label ID="Label107" runat="server" Text="General Patient Teaching Methods Used/Information Given (Check all that apply)" CssClass="rdbBlock"></asp:Label>
<asp:CheckBoxList ID="CheckBoxList6" runat="server" CssClass="rdbBlock">
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Patient/Caregiver observed</span>" Value="Patient/Caregiver observed"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Disease process</span>" Value="Disease process"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Nursing visit frequecy</span>" Value="ursing visit frequecy"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Supply management</span<" Value="Supply management"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Emergency Procedures</span>" Value="Emergency Procedures"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>24 phone number</span>" Value="24 phone number"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Right/Responsibility</span>" Value="Right/Responsibility"></asp:ListItem>
<asp:ListItem Text="&nbsp;&nbsp;<span style=font-weight:normal;>Reviewed infusion admission packet</span>" Value="Reviewed infusion admission packet"></asp:ListItem>
</asp:CheckBoxList>

我想要做的是从选定的 ListItems 中获取值并将这些值设置为标签。我想使用 JavaScript/JQuery,但我不明白。

这是我在文本框上使用的内容,它可以工作,但文本框没有多个选择项可供收集。

YES - VERY IMPORTANT - NO POST BACK!!!!

<script type="text/javascript">
function setLabelText9(e) {
e.preventDefault(); // To prevent postback
var txtValue = $('#<%=txtCaregiverHelper.ClientID%>').val();
$('#<%=Label286.ClientID%>').html(txtValue);
}
function getLabelText9(e) {
e.preventDefault(); // To prevent postback
alert($('#<%=Label286.ClientID%>').html());
}
</script>

期望的结果:如果选中 CheckBoxList ListItem(使用索引)0、3、5,则将标签设置为索引 0、3、5 中的选定值。我可以将一些值连接在一起,这样它看起来就带有空格和标点符号。我只需要 javascript/jquery 代码的帮助来收集所有值并将它们存储在标签文本中。

谢谢

最佳答案

您的 setLabelText9() 方法应更改为读取多个选定值的方式。

        var indexes = []; 
$('#<%=txtCaregiverHelper.ClientID%> :selected').each(function(i, selected){
indexes[i] = $(selected).val();
});
$('#<%=Label286.ClientID%>').html(indexes.join(" "));

关于javascript - ASP JavaScript - CheckBoxList - 将选定值捕获到 Label.Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40895471/

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