ASP.NET jQuery 實例5 (顯示CheckBoxList成員選中的內(nèi)容)
更新時間:2012年01月13日 22:32:19 作者:
這章我們主要看下如何通過jQuery來獲取CheckBoxList成員內(nèi)容
界面代碼:
<form id="form1" runat="server">
<div align="left">
<fieldset style="width: 400px; height: 150px">
<p>
請選擇語言</p>
<asp:CheckBoxList ID="ckbListPro" runat="server">
<asp:ListItem Value="1" Text="C#"></asp:ListItem>
<asp:ListItem Value="2" Text="JAVA"></asp:ListItem>
<asp:ListItem Value="3" Text="C++"></asp:ListItem>
<asp:ListItem Value="4" Text="JavaScript"></asp:ListItem>
</asp:CheckBoxList>
</fieldset>
<br />
<div id="message" style="color:Red;"></div>
</div>
</form>
顯示效果:
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
// CheckBoxList在頁面呈現(xiàn)時轉(zhuǎn)換為<table id="ckbListPro">
// 成員ListItem轉(zhuǎn)換為<input type="checkbox"><label>
$("#<%=ckbListPro.ClientID %>").click(function () {
var str = "";
// 這里獲取到被選中的<input type="checkbox">
$("#<%=ckbListPro.ClientID %> input[type=checkbox]:checked").each(function () {
str = str + $(this).val() + ":" + $(this).next().text() + " "; // 這里的next()表示<label>
});
$("#message").text(str);
});
});
</script>
選中語言后界面:
復(fù)制代碼 代碼如下:
<form id="form1" runat="server">
<div align="left">
<fieldset style="width: 400px; height: 150px">
<p>
請選擇語言</p>
<asp:CheckBoxList ID="ckbListPro" runat="server">
<asp:ListItem Value="1" Text="C#"></asp:ListItem>
<asp:ListItem Value="2" Text="JAVA"></asp:ListItem>
<asp:ListItem Value="3" Text="C++"></asp:ListItem>
<asp:ListItem Value="4" Text="JavaScript"></asp:ListItem>
</asp:CheckBoxList>
</fieldset>
<br />
<div id="message" style="color:Red;"></div>
</div>
</form>
顯示效果:
復(fù)制代碼 代碼如下:
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
// CheckBoxList在頁面呈現(xiàn)時轉(zhuǎn)換為<table id="ckbListPro">
// 成員ListItem轉(zhuǎn)換為<input type="checkbox"><label>
$("#<%=ckbListPro.ClientID %>").click(function () {
var str = "";
// 這里獲取到被選中的<input type="checkbox">
$("#<%=ckbListPro.ClientID %> input[type=checkbox]:checked").each(function () {
str = str + $(this).val() + ":" + $(this).next().text() + " "; // 這里的next()表示<label>
});
$("#message").text(str);
});
});
</script>
選中語言后界面:
相關(guān)文章
基于jquery的復(fù)制網(wǎng)頁內(nèi)容到WORD的實現(xiàn)代碼
基于jquery的復(fù)制網(wǎng)頁內(nèi)容到WORD的實現(xiàn)代碼,需要的朋友可以參考下。2011-02-02jQuery Validation PlugIn的使用方法詳解
這篇文章主要介紹了jQuery Validation PlugIn的使用方法,需要的朋友可以參考下2015-12-12jQuery中each和js中forEach的區(qū)別分析
這篇文章主要介紹了jQuery中each和js中forEach的區(qū)別,結(jié)合實例形式較為詳細(xì)的分析了jQuery中each和js中forEach針對數(shù)組與對象遍歷的相關(guān)操作技巧與注意事項,需要的朋友可以參考下2019-02-02jquery 動態(tài)調(diào)整textarea高度
用jquery實現(xiàn)的調(diào)整textarea高度的實現(xiàn)代碼。這個動畫效果比較流暢。適合新手學(xué)習(xí)。2009-11-11JQuery基于FormData異步提交數(shù)據(jù)文件
這篇文章主要介紹了JQuery基于FormData異步提交數(shù)據(jù)文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09