这只是一个例子:
<script>
$('#mainCat').on('change', function() {
var selected = $(this).val();
$("#expertCat option").each(function(item){
console.log(selected) ;
var element = $(this) ;
console.log(element.data("tag")) ;
if (element.data("tag") != selected){
element.hide() ;
}else{
element.show();
}
}) ;
$("#expertCat").val($("#expertCat option:visible:first").val());
});
</script>
<select id="mainCat">
<option value = '1'>navid</option>
<option value = '2'>javad</option>
<option value = '3'>mamal</option>
</select>
<select id="expertCat">
<option value = '1' data-tag='2'>UI</option>
<option value = '2' data-tag='2'>Java Android</option>
<option value = '3' data-tag='1'>Web</option>
<option value = '3' data-tag='1'>Server</option>
<option value = '3' data-tag='3'>Back End</option>
<option value = '3' data-tag='3'>.net</option>
</select>
我的控制器我想首先选择两个部门,然后选择部门中的职位。我有两种方法,可以返回部门列表和部门位置列表。当我在第一次选择中选择值并在选择两个中返回时,需要帮助如何提供参数。
@GET
@Secured(value = { "ROLE_ADMIN" })
@RequestMapping(value = "/addUser")
public String userForm(User user, Model model,
@RequestParam(name="success", required=false)String success
/*@RequestParam(name="department") int departmentId*/) {
Map<Integer, String> positionMapById = preparePositionMap(departmentId);
Map<Integer, String> departmentMap = prepareDepartmentMap();
model.addAttribute("departmentMap", departmentMap);
model.addAttribute("positionMapById", positionMapById);
model.addAttribute("user", user);
if(success != null) {
if(success.equals("addUser")) {
model.addAttribute("message", "Użytkownik dodany !");
}
}
return "addUser";
}
JSP:
<div class="form-group">
<label>Wybierz Dział</label>
<%-- <form:select id="inputState" class="form-control" path="department"
items="${departmentMap}"/>--%>
<form:select id="inputState" class="form-control" path="department"
onchange="this.id">
<form:option value="${position.id}"> --SELECT--</form:option>
<form:options items="${departmentMap}"></form:options>
</form:select>
</div>
<br />
<div class="form-group">
<label>Wybierz stanowisko</label>
<form:select id="inputState" class="form-control" path="position"
items="${positionMapById}" />
</div>