如何实现在asp.net中js+jquery添加下拉框值和后台获取

发布时间:2021-09-30 15:54:45 作者:iii
来源:亿速云 阅读:114

本篇内容主要讲解“如何实现在asp.net中js+jquery添加下拉框值和后台获取”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何实现在asp.net中js+jquery添加下拉框值和后台获取”吧!

复制代码 代码如下:

<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";//后台获取的数据格式,这里用固定值了
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>为了满足两列,任意多行。后台动态生成下拉框,还要前后列联级的需求。使用js+jquery,用服务器控件+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();
}

到此,相信大家对“如何实现在asp.net中js+jquery添加下拉框值和后台获取”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 如何根据后台返回的值来select下拉框默认选中值
  2. ASP.NET MVC 下拉框传值方式

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

asp.net jquery js

上一篇:在Java中使用HashMap来实现访问的键值对

下一篇:Standard用于管理JavaScript代码怎么写

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》