Javascript调用XML制作连动下拉框
时间:2007-09-17 12:55:00
传统的HTML页面中连动下拉框采用了两种方法:
1)直接将下拉框中的内容hardcode于html的javascript中,调用javascript函数循环写入下拉框中。这种方法不适用于下拉框内容经常改变的情况。因为数据源和javascript程序写死在同一页面。
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; c
harset=gb2312">
<script LANGUAGE="javascript">
<!--
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("徐汇区","01","001");
subcat[1] = new Array("嘉定区","01","002");
subcat[2] = new Array("黄浦区","01","003");
subcat[3] = new Array("南昌市","02","004");
subcat[4] = new Array("九江市","02","005");
subcat[5] = new Array("上饶市","02","006");
onecount=6;
function changelocation(locationid)
{
document.myform.smalllocation.length = 0;
var locationid=locationid;
var i;
document.myform.smalllocation.options[0] = new Option(’====所有地区====’,’’);
for (i=0;i <onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.smalllocation.options[document.myform.smalllocation.length]
= new Option(subcat[i][0], subcat[i][2]);
}
}
}
//-->
</script>
</head>
<body>
<form method="post">
<select
onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)">
<option value="01" selected>上海</option>
<option value="02">江西</option>
</select>
<select >
<option selected value="">==所有地区==</option>
</select>
</form>
<script LANGUAGE="javascript">
<!--
changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value);
//-->
</script>
</body>
</html>
2)javascript 直接读取数据库,取数据库中的记录写入javascript中,然后和第一种方法一样,调用javascript函数循环写入下拉框中。此方法将数据源与javascript分开,但,公开数据库的连接,从安全角度说,没有多少实用价值。
我的方法是将下拉框中的数据放在XML文件中,用javascript读XML文件,取得下拉框中的内容。
标签:xml,下拉框,连动下拉框
0
投稿
猜你喜欢
Explain命令在优化查询中的实际应用
2024-01-20 03:54:13
python实现日常记账本小程序
2023-09-06 18:00:49
解决python3 整数数组转bytes的效率问题
2023-08-09 19:39:41
解决jupyter (python3) 读取文件遇到的问题
2021-02-05 10:00:25
网页绿色系配色应用实例
2008-08-26 11:51:00
Python图像处理库PIL详细使用说明
2021-10-14 17:43:44
利用python发送和接收邮件
2022-01-23 10:22:07
Pycharm中安装pywin32报错问题及解决
2022-09-29 19:58:14
用于WebKit的CSS诀窍[译]
2009-03-11 20:03:00
Python实现的井字棋(Tic Tac Toe)游戏示例
2023-03-08 23:22:34
Matplotlib 折线图plot()所有用法详解
2023-01-30 06:10:30
批标准化层 tf.keras.layers.Batchnormalization()解析
2023-06-18 23:35:17
Dreamweaver量身打造Wordpress留言板(三)
2009-12-13 18:45:00
利用python实现万年历的查询
2023-02-24 03:16:01
oracle逻辑运算符与其优先级简介
2023-07-15 00:28:26
Mysql中的事务是什么如何使用
2024-01-21 18:42:26
Vite引入虚拟文件的实现
2024-05-21 10:30:54
py中的目录与文件判别代码
2023-06-01 03:32:06
python分割一个文本为多个文本的方法
2022-09-01 06:40:33
python 判断txt每行内容中是否包含子串并重新写入保存的实例
2023-11-28 06:34:56