未选中客户端时获取Checkboxlist值 [英] Get the Checkboxlist value when unchecked Client-Side
本文介绍了未选中客户端时获取Checkboxlist值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当未选中项目时如何获取Checkboxlist值的值?我尝试了以下代码,但没有获得价值.请让我知道.
How to get the value of Checkboxlist value when item is unchecked? I tried the following code but I am not getting the value. Please let me know.
JQuery
----------------
$(document).ready(function () {
$("#<%=chkboxTypeList.ClientID%> input[type=checkbox]").click(function () {
if (!this.checked) {
alert($(this).val());
}
});
.aspx
-------------------
<asp:CheckBoxList ID="chkboxTypeList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="TEST 1" Value="1"></asp:ListItem>
<asp:ListItem Text="TEST 2" Value="2"></asp:ListItem>
<asp:ListItem Text="TEST 3" Value="3"></asp:ListItem>
</asp:CheckBoxList>
推荐答案
checkboxlist
的值存储在Viewstate
中,而不呈现在客户端.
The values of checkboxlist
are stored in Viewstate
and not rendered clientside.
获取价值客户端的一种方法是使用Attribute
.
One way of getting the value client side is using a Attribute
.
<asp:CheckBoxList ID="chkboxTypeList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="TEST 1" Value="1" ClientValue="1"></asp:ListItem>
<asp:ListItem Text="TEST 2" Value="2" ClientValue="2"></asp:ListItem>
<asp:ListItem Text="TEST 3" Value="3" ClientValue="3"></asp:ListItem>
</asp:CheckBoxList>
然后呈现为:-
<td>
<span clientvalue="2">
<input id="chklstStates_1" type="checkbox" name="chklstStates$1">
<label for="chklstStates_1">TEST 2</label>
</span>
</td>
然后使用:-
$(document).ready(function () {
$("#<%=chkboxTypeList.ClientID%> input[type=checkbox]").change(function () {
var value = $(this).parent().attr('clientvalue');
if (!this.checked) {
alert(value);
}
});
});
这篇关于未选中客户端时获取Checkboxlist值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文