溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何實現(xiàn)在asp.net中js+jquery添加下拉框值和后臺獲取

發(fā)布時間:2021-09-30 15:54:45 來源:億速云 閱讀:116 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“如何實現(xiàn)在asp.net中js+jquery添加下拉框值和后臺獲取”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“如何實現(xiàn)在asp.net中js+jquery添加下拉框值和后臺獲取”吧!

復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".cg2").change(function () {
var id = $(this).attr("id");
var value = $(this).val();
var newid = '#'+id.replace('_1_', '_2_');//把第一列id替換成第二列id
//alert(newid);
var data = "t1*v1|t2*v2|t3*v3";//后臺獲取的數(shù)據(jù)格式,這里用固定值了
var datas = data.split('|');//分割成多組
for (var i = 0; i < datas.length; i++) {
var d1 = datas[i].split('*');//每組分割成 顯示值和真實值
$(newid).append("<option value=\""+d1[1]+"\">" + d1[0] + "</option>");
//alert(d1);
}
// alert(id + "|||" + value);
});
})

</script>
</head>
<body>
<form id="form1" runat="server">
<div>為了滿足兩列,任意多行。后臺動態(tài)生成下拉框,還要前后列聯(lián)級的需求。使用js+jquery,用服務(wù)器控件+Ajax也不行,老是選擇之后就
<asp:DropDownList ID="ddl_1_1" CssClass="cg2" runat="server">
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem>
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem>
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddl_2_1" runat="server">
</asp:DropDownList><br/>
<asp:DropDownList ID="ddl_1_2" CssClass="cg2" runat="server">
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem>
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem>
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddl_2_2" runat="server">
</asp:DropDownList><br/>
<asp:Button ID="ButtonGet" runat="server" Text="獲取" onclick="ButtonGet_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

//后臺

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

}
}

protected void ButtonGet_Click(object sender, EventArgs e)
{
///獲取通過js加選擇的 ddl_2_1 控件選中的值,顯示在Label1上。
Label1.Text = Request["ddl_2_1"].ToString();
}

到此,相信大家對“如何實現(xiàn)在asp.net中js+jquery添加下拉框值和后臺獲取”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI