标签:class script asc change 复选框 ext lse 注意事项 length
1.引jquery包
<script type="text/javascript">
$(function () {
//根据学院动态填充专业
$("[name=depart]").change(function () {
var did= $(this).val();
if (did==-1){
alert("请选择学院");
$("[name=major]")[0].length=0;//[0]-->将jquery改为js
$("[name=major]")[0].add(new option("请选择",-1));//-->动态填充option复选框
} else {
$.ajax({
url: "/Educational/class/getallmajor",
data: "did" + did,
type: "post",
dataType: "json",
success: function (rs) {
$("[name=major]")[0].length=0;
$("[name=major]")[0].add(new option("请选择",-1));
for (var i = 0; i < rs.length; i++) {
$("[name=major]")[0].add(new Option(rs[i].majorname, rs[i].majorid));
}
}
})
}
})
//动态确定班主任
$("[name=majorid]").change(function () {
var did= $("[name=deptid]").val();
var mid = $(this).val();
if (mid==-1) {
alert("请选择专业");
}
$.ajax({
url: "/Educational/class/getrolename",
data: "did" + did+"&mid="+mid,
type: "post",
dataType: "json",
success:function (rs) {
$("[name=classteacher]")[0].length=0;
for (var i = 0; i < rs.length; i++) {
$("[name=classteacher]")[0].add(new Option(rs[i].userName, rs[i].userName));
}
}
})
})
})
标签:class script asc change 复选框 ext lse 注意事项 length
原文地址:https://www.cnblogs.com/yunshao/p/9813655.html