Select级联菜单,用Ajax获取Json绑定下拉框(jQuery)
需求类似这样 ↓ ↓ ↓
--》 
菜单A发生变化,动态取数据填充下拉菜单B。
JS代码如下:
<script type="text/javascript">
$(function () {
$("#TeamSelect").change(function () { var tid = $("#TeamSelect option:selected").val();
$.ajax({
url: "/ajax/ajaxGetManagerByTeam.aspx?teamId="+tid,
type: "Post",
contentType: "application/json",
dataType: "json",
success: function (data) {
var ddl = $("#ManagerSelect");
//删除节点
$("#ManagerSelect option").remove();
//转成Json对象
var result = eval(data);
//循环遍历 下拉框绑定
$(result).each(function (key) {
//添加option 对应Json对象名称
var opt = $("<option></option>").text(result[key].ManagerName).val(result[key].ManagerID);
ddl.append(opt);
});
},
error: function () {
alert("Error");
}
});
});
}); </script>
ajaxGetManagerByTeam.aspx.cs页面代码如下:
protected void Page_Load(object sender, EventArgs e)
{
var teamId = ;
try
{
var teamIdStr = Request.QueryString["teamId"];
if (!string.IsNullOrEmpty(teamIdStr))
{
int.TryParse(teamIdStr, out teamId);
DataTable dt = GetManager(teamId); //GetManager()是一个返回DataTable类型数据的方法
string proStr = JsonConvert.SerializeObject(dt); //将DataTable序列化为Json格式的字符串
Response.ContentType = "text/plain";
Response.Write(proStr); }
}
catch(Exception ex)
{
Response.Write(ex);
} }
另可给Select添加默认项:
$("#ManagerSelect").append("<option value='-1'>全部</option>");
//或者
$("#ManagerSelect")[].options.add(new Option("全部", "-1"));
Select级联菜单,用Ajax获取Json绑定下拉框(jQuery)的更多相关文章
- 奥展项目笔记07--vue绑定下拉框和checkbox总结
1.vue绑定下拉框 <div class="col-md-1 data"> <select class="form-control " v- ...
- MVC联想查询绑定下拉框
前言 在做搜索时,输入些内容时需要弹出下拉框给用户进行选择,极大的方便了用户,会给用户带来不一样的体验 Controller public ActionResult SSAC(string UserN ...
- WPF AutoGeneratingColumn 绑定下拉框
WPF自动产生列,前台代码: <DataGrid x:Name="Dg" AutoGenerateColumns="True" CanUserAddRow ...
- 关于safari上的select宽高问题小技,自定义下拉框
之前一直用windows做开发,最近换了个mac,在几经折腾之下,安装完了各种开发工具,IDE等,然后欣然打开自己正在开发的网站.突然发现mac上所有的下拉框都变了,都是默认样式,无论padding, ...
- vue 获取数据联动下拉框select ,并解决报Duplicate value found in v-for="...": "". Use track-by="$index" 错误
公司项目中遇到一个问题,联动下拉框,并且数据是使用vue-resource从后台获取的,格式不利于输出联动下拉框,联动下拉框是第一个下拉框输出一个数组里每一项json的一个text值,从而第二下拉框输 ...
- JQ与AJAX 省市区三级联动下拉框
用于初学者学习基本的联动下拉框,废话不多说,见代码 首先看控制器里的3个下拉框对应代码: public ActionResult GetProvinceList() { ProvinceReposit ...
- MVC4 绑定下拉框方法,解决编辑时不绑定值
方法一 Controller 部分代码: public ActionResult Modify(int id) { //3.1.1 检查id //3.1.2根据id查询数据 Models.Stude ...
- js绑定下拉框
---恢复内容开始--- 方法一 js-ajax部分 function GetDListOfCt() { $.ajax({ url: "../../Ajax/Boss_Show.ashx?t ...
- jquery easyui无法绑定下拉框内容
最近在研究jquery easyui的DataGrid,发现DataGrid中的下拉框无法绑定值,找了很久也没发现是具体问题所在,最后还是同事帮忙搞定的.具体问题竟然是jquery easyui提供的 ...
随机推荐
- LeetCode之Symmetric Tree
</pre>Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ce ...
- Python并行编程(十):多线程性能评估
1.基本概念 GIL是CPython解释器引入的锁,GIL在解释器层面阻止了真正的并行运行.解释器在执行任何线程之前,必须等待当前正在运行的线程释放GIL,事实上,解释器会强迫想要运行的线程必须拿到G ...
- Flask之中间件
from flask import Flask, flash, redirect, render_template, request app = Flask(__name__) app.secret_ ...
- ssm之mapper异常 Result Maps collection already contains value for com.ssj.mapper.UserMapper 和 Type interface com.ssj.mapper.UserMapper is already known to the MapperRegistry.
异常一:Result Maps collection already contains value for com.ssj.mapper.XXXMapper 原因分析:XXXmapper.xml文件中 ...
- MyEclipse 10的使用技巧
默认快捷键 :Shift+Alt+s 然后选择generater getter and setter,这是快捷键.或者右键source里边有 generater getter and setter. ...
- PAT 1063 Set Similarity[比较]
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...
- C++学习笔记-操作符重载
操作符重载(operator overloading)是一种形式的C++多态,C++将操作符重载扩展到用户自定义的类型,如允许使用+将两个自定义的对象相加,编译器将根据操作数的数目和类型决定使用那种加 ...
- The Cheap KD 10 design is not too far of a departure
Kevin Durant's Cheap KD 10 have to do with to determine the greatest spotlight they have seen around ...
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree
地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 second ...
- python在CentOS 7中的安装
CentOS 7 中默认安装了python2.7.5,可能部分开发人员需要使用python3系列的产品,因为版本不“向下”兼容,诸如print函数,因此需要对于不同的项目进行python版本之间的切换 ...