html:
<select name="BanZuCode" οnclick="showsmsselect()" >
js:
function showsmsselect() {
var pdid = "BanZuCode" + a;
var BanZuCode = $("#" + pdid + "").val();
if (BanZuCode==null) {
$.ajax({
type:"post",
url: "basePath",
dataType: "json",
success: function (data) {
var optArr = [];
$("#" + pdid + "").empty();
for (var i = 0; i < data.length; i++) {
$("#" + pdid + "").append("<option value=" + data[i].FName + ">" + data[i].FName + "</option>");
}
// 缺一不可
$("#" + pdid + "").selectpicker("refresh");
$("#" + pdid + "").selectpicker("render");
});
controller:
public ActionResult basePath() {
string where1 = "Note="條件"";
//查詢加班人員
Data.BLL.BanZu bz = new Data.BLL.BanZu();
List<Data.Model.BanZu> listbz = bz.FindBanZu(where1);
return Json(listbz, JsonRequestBehavior.AllowGet);
因為我做的是新增一行下拉框,所以id是給的動態的。我用的bootstrap框架,看了下應該也適合java,改下controller就可以了
html:
<select name="BanZuCode" οnclick="showsmsselect()" >
js:
function showsmsselect() {
var pdid = "BanZuCode" + a;
var BanZuCode = $("#" + pdid + "").val();
if (BanZuCode==null) {
$.ajax({
type:"post",
url: "basePath",
dataType: "json",
success: function (data) {
var optArr = [];
$("#" + pdid + "").empty();
for (var i = 0; i < data.length; i++) {
$("#" + pdid + "").append("<option value=" + data[i].FName + ">" + data[i].FName + "</option>");
}
// 缺一不可
$("#" + pdid + "").selectpicker("refresh");
$("#" + pdid + "").selectpicker("render");
}
});
}
}
controller:
public ActionResult basePath() {
string where1 = "Note="條件"";
//查詢加班人員
Data.BLL.BanZu bz = new Data.BLL.BanZu();
List<Data.Model.BanZu> listbz = bz.FindBanZu(where1);
return Json(listbz, JsonRequestBehavior.AllowGet);
}
因為我做的是新增一行下拉框,所以id是給的動態的。我用的bootstrap框架,看了下應該也適合java,改下controller就可以了