ajax实现二级动态联动问题
JSP:<tr><tdalign="right"width="20%"><labelfor="role">职位:</label></td><tdalign="left"w...
JSP:
<tr>
<td align="right" width="20%"><label for="role">职位:</label></td>
<td align="left" width="80%">
<select id="role" name="role" class="input">
<s:iterator id="item" value="#request.roleList">
<option value="<s:property value="#item.id"/>" <s:if test="resultBean.role_id== #item.id"> selected="selected" </s:if>>
<s:text name="%{getText(#item.roleName)}" />
</option>
</s:iterator>
</select>
</td>
</tr>
<tr>
<td align="right" width="20%"><label for="managerName">上级经理姓名:</label></td>
<td align="left" width="80%">
<select id="managerName" name="managerName" class="input">
<s:iterator id="item" value="#request.userManagerList">
<option value="<s:property value="#item.manager_ID"/>" <s:if test="resultBean.manager_ID==#item.manager_ID"> selected="selected" </s:if>>
<s:text name="%{getText(#item.managerName)}" />
</option>
</s:iterator>
</select>
</td>
</tr>
后台:
public void initRoleHaha() {
System.out.print(1);
Map params = super.getParams();
String role = String.valueOf(params.get("role"));
if(role=="1"){
List userManagerList = service.query("search_role1");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}else if(role=="5"){
List userManagerList = service.query("search_role5");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}else{
List userManagerList = service.query("search_roleOther");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}
其中QUERY是封装好的。
现在问题是前台失去焦点不会刷新下面的SELECT框。不知道后台写的对不对。前台JS也不知道怎么写。
下面是我写的:
$("#role").blur( function() {
$.ajax({
type :"POST",
url :"userHandler!initRoleHaha.action?role=" + convertCode($("#role").val()),
data :'',
success : function() {
$("#item").val("#request.userManagerList");
alert(resultList);
},
error : function() {
$("#item").val("#request.userManagerList");
alert(resultList);
return;
}
});
}) 展开
<tr>
<td align="right" width="20%"><label for="role">职位:</label></td>
<td align="left" width="80%">
<select id="role" name="role" class="input">
<s:iterator id="item" value="#request.roleList">
<option value="<s:property value="#item.id"/>" <s:if test="resultBean.role_id== #item.id"> selected="selected" </s:if>>
<s:text name="%{getText(#item.roleName)}" />
</option>
</s:iterator>
</select>
</td>
</tr>
<tr>
<td align="right" width="20%"><label for="managerName">上级经理姓名:</label></td>
<td align="left" width="80%">
<select id="managerName" name="managerName" class="input">
<s:iterator id="item" value="#request.userManagerList">
<option value="<s:property value="#item.manager_ID"/>" <s:if test="resultBean.manager_ID==#item.manager_ID"> selected="selected" </s:if>>
<s:text name="%{getText(#item.managerName)}" />
</option>
</s:iterator>
</select>
</td>
</tr>
后台:
public void initRoleHaha() {
System.out.print(1);
Map params = super.getParams();
String role = String.valueOf(params.get("role"));
if(role=="1"){
List userManagerList = service.query("search_role1");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}else if(role=="5"){
List userManagerList = service.query("search_role5");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}else{
List userManagerList = service.query("search_roleOther");
getHttpRequest().setAttribute("userManagerList", userManagerList);
}
其中QUERY是封装好的。
现在问题是前台失去焦点不会刷新下面的SELECT框。不知道后台写的对不对。前台JS也不知道怎么写。
下面是我写的:
$("#role").blur( function() {
$.ajax({
type :"POST",
url :"userHandler!initRoleHaha.action?role=" + convertCode($("#role").val()),
data :'',
success : function() {
$("#item").val("#request.userManagerList");
alert(resultList);
},
error : function() {
$("#item").val("#request.userManagerList");
alert(resultList);
return;
}
});
}) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询