ASP.NET jQuery 實(shí)例5 (顯示CheckBoxList成員選中的內(nèi)容)
更新時(shí)間:2012年01月13日 22:32:19 作者:
這章我們主要看下如何通過(guò)jQuery來(lái)獲取CheckBoxList成員內(nèi)容
界面代碼:
<form id="form1" runat="server">
<div align="left">
<fieldset style="width: 400px; height: 150px">
<p>
請(qǐng)選擇語(yǔ)言</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在頁(yè)面呈現(xiàn)時(shí)轉(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>
選中語(yǔ)言后界面:
復(fù)制代碼 代碼如下:
<form id="form1" runat="server">
<div align="left">
<fieldset style="width: 400px; height: 150px">
<p>
請(qǐng)選擇語(yǔ)言</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在頁(yè)面呈現(xiàn)時(shí)轉(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>
選中語(yǔ)言后界面:
相關(guān)文章
jQuery打印指定區(qū)域Html頁(yè)面并自動(dòng)分頁(yè)
項(xiàng)目中需要用到打印HTML頁(yè)面,需要指定區(qū)域打印,使用jquery.PrintArea.js 插件實(shí)現(xiàn)分頁(yè),需要的朋友可以參考下2014-07-07jQuery點(diǎn)擊出現(xiàn)愛(ài)心特效
這篇文章主要為大家詳細(xì)介紹了jQuery點(diǎn)擊出現(xiàn)愛(ài)心特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08基于jquery的復(fù)制網(wǎng)頁(yè)內(nèi)容到WORD的實(shí)現(xiàn)代碼
基于jquery的復(fù)制網(wǎng)頁(yè)內(nèi)容到WORD的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-02-02jQuery Validation PlugIn的使用方法詳解
這篇文章主要介紹了jQuery Validation PlugIn的使用方法,需要的朋友可以參考下2015-12-12jQuery中each和js中forEach的區(qū)別分析
這篇文章主要介紹了jQuery中each和js中forEach的區(qū)別,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery中each和js中forEach針對(duì)數(shù)組與對(duì)象遍歷的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2019-02-02jquery 動(dòng)態(tài)調(diào)整textarea高度
用jquery實(shí)現(xiàn)的調(diào)整textarea高度的實(shí)現(xiàn)代碼。這個(gè)動(dòng)畫(huà)效果比較流暢。適合新手學(xué)習(xí)。2009-11-11JQuery基于FormData異步提交數(shù)據(jù)文件
這篇文章主要介紹了JQuery基于FormData異步提交數(shù)據(jù)文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09