AJAX和select,绑定值,动态加载select的Item值,设置所选的值 (全都是客户端控件)

//根据年级获取班级

function btnGetBJ(njm,bh) {
$.ajax({
cache: false,
type: "GET",
url: 'TPJG.ashx?HandlerType=getbj&njm=' + njm + '&xqh=' + $('#seletXQ option:selected').val(),
dataType: 'json',
success: function (json) {
//AJAX加载select
if (json != "" || json != null || json != undefined) {
document.getElementById("seletBJ").innerHTML = "";
document.getElementById('seletBJ').add(new Option("---", ""));
for (var i = 0; i < json.length; i++) {
document.getElementById('seletBJ').add(new Option(json[i].texts, json[i].values));
}
//设置选中项
if (bh != "") {
var all_options = document.getElementById("seletBJ").options;
for (var j = 0; j < all_options.length; j++) {
if (all_options[j].value == bh) {
all_options[j].selected = true;
}
}
}
}
}
});
}
//页面初始化时,加载select的选择项
$(function () {
btnGetBJ('<%= njm %>', '<%= bh %>');
})

 

 

//后台绑定select,设置选择项

<option value="">---</option>
<% foreach (var dic in xqList)
{ %><option value="<%= dic.XQH %>" <%= Request.QueryString["seletXQ"] == dic.XQH ?"selected":""%>>
<%= dic.XQMC%></option>
<% } %>
</select>

posted on 2015-04-14 16:37  win_your_lo  阅读(279)  评论(0编辑  收藏  举报