jsp中select的onchange事件用法实例

作者:hacker0825 时间:2024-04-19 09:58:23 

本文实例讲述了jsp中select的onchange事件用法。分享给大家供大家参考,具体如下:


<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
int count = 0;
java.sql.ResultSet rs1 = DBManage.executeQuery("select hydm,zhydm,zhymc from zhy ");//读取数据
while(rs1.next())
{
String selhydm=rs1.getString("hydm").trim();
String zhydm=rs1.getString("zhydm").trim();
String zhymc=rs1.getString("zhymc").trim();
%>
subcat[<%=count%>] = new Array("<%=zhydm%>","<%=selhydm%>","<%=zhymc%>");//产生数组
<%
count = count + 1;
}
if(rs1!=null) DBManage.closeCOnn();
%>
onecount=<%=count%>;
function changelocation(id)
{
document.form1.selzhy.length = 0;
var hydm=id;
var i;
document.form1.selzhy.options[0] = new Option('选择子行业分类','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == hydm)
{
document.form1.selzhy.options[document.form1.selzhy.length] = new Option(subcat[i][2], subcat[i][0]);
}  
}
}
</script>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="180" height="20" align="right">选择行业分类:</td>
<td width="320">
<select name="selhy" onChange="changelocation(document.form1.selhy.options[document.form1.selhy.selectedIndex].value)" size="1" >
<option value="2">请选择行业分类</option>
<%
rs = DBManage.executeQuery("select * from hy");
while(rs.next())
{
 String hydm=rs.getString("hydm").trim();
 String hymc=rs.getString("hymc").trim();
%>
<option value="<%=hydm%>"><%=hymc%></option>
<%
}
if(rs!=null) DBManage.closeCOnn();
%>
</select>
</td>
</tr>
<tr>
<td height="20" align="right">选择子行业分类:</td>
<td>
<select name="selzhy" >
<option value="" selected>请选择子行业分类</option>
</select>
</td>
</tr>
</table>

<form name=form1>
<select name=province onchange="cityName(this.selectedIndex)">
 <option value="">请选择省名</option>
</select>
<select name=city>
 <option value="">请选择城名</option>
</select>
</form>

<script language=javascript>
var city1 = ["杭州", "宁波", "温州", "绍兴", "金华", "湖州"];
var city2 = ["南京", "苏州", "无锡", "常州", "镇江", "徐州"];
var city3 = ["合肥", "翕县", "黄山", "祁门", "休宁"];
var city4 = ["南昌", "九江", "赣州", "上饶", "新余", "景德镇"];  
var provinceName = ["浙江", "江苏", "安徽", "江西"];
function province()
{
  var e = document.form1.province;
  for (var i=0; i<provinceName.length; i++)
   e.options.add(new Option(provinceName[i], provinceName[i]));
}
function cityName(n)
{
  var e = document.form1.city;
  for (var i=e.options.length; i>0; i--)  e.remove(i);
  if (n == 0) return;
  var a = eval("city"+ n); //得到城市的数组名
  for (var i=0; i<a.length; i++) e.options.add(new Option(a[i], a[i]));
}
function window.onload()
{
  province(); //初始时给省名下拉菜单赋内容
}
</script>

希望本文所述对大家JSP程序设计有所帮助。

标签:jsp,select,onchange
0
投稿

猜你喜欢

  • Windows下MySQL 5.7无法启动的解决方法

    2024-01-26 02:32:31
  • 通过索引优化含ORDER BY的MySQL语句

    2010-03-13 12:20:00
  • OpenCV角点检测的实现示例

    2023-06-25 06:49:10
  • Django文件上传与下载(FileFlid)

    2023-07-10 11:33:33
  • 一篇文章弄懂Python中的内建函数

    2023-01-18 00:36:36
  • python3实现磁盘空间监控

    2023-07-09 14:12:49
  • 去掉CSS赘余代码,CSS可以更简洁

    2008-11-05 13:07:00
  • Pandas时间数据处理详细教程

    2022-04-29 03:14:22
  • Python中列表的常用操作详解

    2022-07-17 10:16:42
  • 一文教你彻底解决Python包下载慢问题

    2023-04-02 20:29:32
  • python初学定义函数

    2021-07-02 03:37:07
  • 通过实例解析Python调用json模块

    2022-09-22 02:05:06
  • perl特殊符号及默认的内部变量

    2023-08-08 02:13:20
  • python中requests模块的使用方法

    2021-12-27 23:16:29
  • js常用排序实现代码

    2023-08-30 08:50:24
  • Windows下MySQL8.0.11社区绿色版安装步骤图解

    2024-01-14 23:02:34
  • python根据unicode判断语言类型实例代码

    2021-08-22 18:24:04
  • Linux系统下导出ORACLE数据库出现Exporting questionable statistics.错误 处理

    2010-07-16 13:27:00
  • 详解Oracle在out参数中访问光标

    2024-01-12 21:17:50
  • pygame外星人入侵小游戏超详细开发流程

    2021-06-15 05:15:47
  • asp之家 网络编程 m.aspxhome.com