在ajax版块没人理.到这里来发.人气多
在网上找了一下,依照一篇文章的思路,具体出处哪里忘记了.改了一下,感觉还行.如果是单纯的国家地区的不必要写在数据库里,因为不会经常改动,写成xml就行了.如果是产品品牌,类别,产品名称这样的搜索就最好写在数据库里,因为后台需要时常更新.
首先建立一个xml文件
Area.xml
文件如下:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<Root>
<country name= "中国 " id= "1001 ">
<province name= "广东 " id= "1001001 ">
<city name= "深圳 " id= "1001001001 "> </city>
<city name= "广州 " id= "1001001002 "> </city>
<city name= "珠海 " id= "1001001003 "> </city>
<city name= "东莞 " id= "1001001004 "> </city>
</province>
<province name= "浙江 " id= "1001002 ">
<city name= "杭州 " id= "1001002001 "> </city>
<city name= "温州 " id= "1001002002 "> </city>
</province>
</country>
<country name= "American " id= "1002 ">
<province name= "califonia " id= "1002001 ">
<city name= "newyork " id= "1002001001 "> </city>
</province>
</country>
</Root>
内容分三级:国家,省份,城市,每个节点都有id,name属性.分别显示在select的value和text里面
其次新建立一web页面,如test.aspx
内容如下:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "test.aspx.cs " Inherits= "test " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript " type= "text/javascript ">
//首先需要初始化
var xmlDoc;
var nodeIndex;
function getxmlDoc()
{
xmlDoc=new ActiveXObject( "Microsoft.XMLDOM ");
var currNode;
xmlDoc.async=false;
xmlDoc.load( "Area.xml ");