页面:
<script type='text/javascript' src='dwr/interface/timeLimitMVManager.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<tr>
<th>
<fmt:message key="timelimitmv.tyep.name"/>
</th>
<td>
<select name="match_type_work_char_id" onchange="changeType(this)" id="match_type_work_char_id">
<option value=""><fmt:message key="msgtem.default" /></option>
<option value="1"><fmt:message key="timelimitmv.type1"/></option>
<option value="2"><fmt:message key="timelimitmv.type2"/></option>
<option value="4"><fmt:message key="timelimitmv.type4"/></option>
</select>
</td>
</tr>
<tr>
<th>
<fmt:message key="timelimitmv.value.name"/>
</th>
<td>
<select name="begin_value" id="begin_value">
<option value="1" ><fmt:message key="timelimitmv.type1"/></option>
<option value="2"><fmt:message key="timelimitmv.type2"/></option>
<option value="4"><fmt:message key="timelimitmv.type4"/></option>
</select>
</td>
</tr>
{
var match_type_work_char_id=sel_obj.value;
if(match_type_work_char_id=='')
return;
timeLimitMVManager.getVNByTN(match_type_work_char_id,showValue);
}
function showValue(dis)
{
DWRUtil.removeAllOptions('begin_value');
DWRUtil.addOptions('begin_value',dis,'begin_value','value_name');
}
dwr.xml:
<allow>
<create creator="spring" javascript="timeLimitMVManager">
<param name="beanName" value="timeLimitMVManager"/> --由SPRING进行管理的MANAGER名称--
<include method="getVNByTN"/> --暴露给页面的方法--
</create>
</allow>
manager方法:
public List getVNByTN(String match_type_work_char_id) {
// TODO Auto-generated method stub
List obs=null;
if(match_type_work_char_id!=null){
if(match_type_work_char_id.equals("1")){
obs=timeLimitMVDAO.getSBLXById();
}
if(match_type_work_char_id.equals("2")){
obs=timeLimitMVDAO.getKUPPById();
}
if(match_type_work_char_id.equals("4")){
obs=timeLimitMVDAO.getCXBZById();
}
}
return obs;
}
本文介绍了一个使用DWR(Direct Web Remoting)实现动态下拉框选项加载的案例。当用户选择特定类型后,通过Ajax调用后台获取对应的数据,并更新另一个下拉框的内容。涉及的技术包括JavaScript、Ajax及后台的Java处理。
144

被折叠的 条评论
为什么被折叠?



