我想编写一个脚本来禁用与第一个下拉列表中选择的值相关的下拉列表(数字 2)。我正在使用脚本标签在第一个下拉列表中编写函数和 onchange 属性,但它不起作用。请查看代码并给我解决方案。
表单.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
function changeDrop() {
// Get current value
var val= document.getElementById("ttype").value;
$("#aap_name").attr("disabled", val=="Common");
};
</script>
</head>
<body>
<form:form id="tfnewsearch" modelAttribute="err_model">
<table cellpadding="1" cellspacing="1" height="250px" style="border-collapse: collapse">
<tr>
<td><form:label path="Err_type">Error Type</form:label></td>
<td><form:select id="ttype" name="Err_type" path="Err_type" items="${Type_list}" onchange="changeDrop();">
</form:select>
</td>
</tr>
<tr>
<td><p>Application </p></td>
<td><form:select id="aap_name" path="Err_application" items="${App_list}">
</form:select>
</td>
</tr>
</table>
</form:form>
</body>
</html>
我的控制器是
@RequestMapping(value="/form",method=RequestMethod.GET)
public String AddError(@ModelAttribute("err_model") ErrorModel errorModel,Map<String, Object> model) {
List<String> Type_list = new ArrayList<String>();
Type_list.add("--Select--");
Type_list.add("Common");
Type_list.add("Specific");
List<String> App_list =errorService.listapplications();
model.put("Type_list", Type_list);
model.put("App_list", App_list);
return "form";
}