Jquery实现两级下拉框

在公司写了一个两级下拉框,用了Jquery框架,初次简单的使用了一下,感觉很好,以后用的机会会很多。

JSP页面的代码:

<table>
<tr>
<td>
<select class="inputitem" name="sheng" id="sheng" style="width:98px;color:#003366" onChange="abc();">
<option selected value="0">选择省份</option>
<% Iterator it=list.iterator();
while(it.hasNext()){
Sheng sheng=(Sheng)it.next();
%>
<option value="<%=sheng.getSid() %>" ><%=sheng.getSheng() %></option>
<%
}
%>

</select>
->
</td>
<td id = "aa">
<select id="a" >
<option value="0">选择市</option>
</select>

</td>
</tr>
</table>

JS关键代码:

<script>

function abc(){
var sheng=document.getElementById('sheng').value;
$.get("shi.do?t="+Math.random()+"&shengID="+sheng,function callback(data){ //将节点的数据发给服务端/shi ,当加载成功时调用function (data)
$("#aa").html(data); //将从服务端的数据输入到id ="aa"的标签里。
});

}

</script>

Action代码:

ServletOutputStream out=response.getOutputStream(); //获得ServletOutputStream的对象out
StringBuffer sb=new StringBuffer();
sb.append("<select name='shi' id='shi' align='left'><option value='0' id='s'>选择市</option>");
for(int i=0;i<list.size();i++){
Shi shi=list.get(i);
sb.append("<option value="+shi.getSid()+">"+shi.getShi()+"</option>");
}
sb.append("</select>");
out.print(sb.toString());//输出字符串数据到JSP页面上



截了一个图,好像看不出效果。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值