利用xml的一个例子,修改其中xml数据岛即可XMLRelatingSel.htm<body onload="XMLRelatingSel(0);"><xml id="XMLData">
<country>
<province text="Beijing" value="北京">
<city text="Beijing" value="北京">
<street text="Si Huan Lu" value="四环路" />
<street text="Xue Yuan Lu" value="学院路" />
</city>
</province>
<province text="Hen Nan" value="河南">
<city text="Zheng Zhou" value="郑州">
<street text="Zhong Yuan Lu" value="中原路"/>
<street text="Da Xue Lu" value="大学路"/>
</city>
<city text="Xin Xiang" value="新乡">
<street text="Ping Yuan Lu" value="平原路" />
<street text="Ren Min Lu" value="人民路" />
</city>
</province>
<province text="Hei Bei" value="河北">
<city text="Shi Jia Zhuang" value="石家庄">
<street text="Ren Min Lu" value="人民路" />
</city>
</province>
</country>
</xml>
<table width = 80% border=1>
<tr>
<td width = 50% align = center>
请选择省份:
</td>
<td width = 50% align = center>
<select name=province></select>
</td>
</tr>
<tr>
<td width = 50% align = center>
请选择城市:
</td>
<td width = 50% align = center>
<select name=city></select>
</td>
</tr>
<tr>
<td width = 50% align = center>
请选择街道:
</td>
<td width = 50% align = center>
<select name=street></select>
</td>
</tr>
</table>
</body>
<SCRIPT LANGUAGE="JavaScript">
<!--
// by qiushuwuhen
// moonpiaza edit 6.1
var aSel=["province","city","street"];
function XMLRelatingSel(p_nSel)
{ var i;
var aTmpVal = new Array();
var nSel = p_nSel; for(i=0; i<nSel; i++)
{
aTmpVal[i] = document.all(aSel[i]).options[document.all(aSel[i]).selectedIndex].value;
} if(nSel == aSel.length)
{
var sSelVal = "";
for(i=0; i<nSel; i++)
{
sSelVal += aSel[i] + ": " + aTmpVal[i] + "\n";
}
alert(sSelVal); return;
} with(document.all(aSel[nSel]))
{
length = 0 ;
var oNode = XMLData.XMLDocument.childNodes[0]; for(i=0; i<nSel; i++)
{
oNode = oNode.selectSingleNode(aSel[i] + '[@value="' + aTmpVal[i] + '"]');
} for(i=0; i<oNode.childNodes.length; i++)
{
length++ ;
options[(length-1)].text = oNode.childNodes[i].getAttribute("text");
options[(length-1)].value = oNode.childNodes[i].getAttribute("value");
} onchange = new Function("XMLRelatingSel("+(nSel+1)+")");
onchange();
}
}//-->
</SCRIPT>:_)

解决方案 »

  1.   

    不好意思啊,不会xml啊,能搞成html的吗?
      

  2.   

    修改其中
    1.属性text的值为下拉菜单的显示值(text)
    2.属性value的值为下拉菜单的显示值(value)
    html的例子,可以用google搜索一下
    <html>
    <head>
    <title>Search Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
    <!--
    menu=new Array();
    myurl=new Array();
    menu[0]="第一节  企业及其类型"; myurl[0]="../content/kcjj/chap01/se01/jjframe.htm";
    menu[1]="第二节  企业经营方式"; myurl[1]="../content/kcjj/chap01/se02/jjframe.htm";
    menu[2]="第三节  企业组织形式"; myurl[2]="../content/kcjj/chap01/se03/jjframe.htm";
    menu[3]="第一节  企业管理的产生与二重性"; myurl[3]="../content/kcjj/chap02/se01/jjframe.htm";
    menu[4]="第二节  企业管理的职能、任务和内容"; myurl[4]="../content/kcjj/chap02/se02/jjframe.htm";
    menu[5]="第三节  企业管理的方法"; myurl[5]="../content/kcjj/chap02/se03/jjframe.htm";
    menu[6]="第四节  企业管理的基础工作"; myurl[6]="../content/kcjj/chap02/se04/jjframe.htm";
    menu[7]="第一节  企业的领导体制"; myurl[7]="../content/kcjj/chap03/se01/jjframe.htm";
    menu[8]="第二节  企业的组织机构"; myurl[8]="../content/kcjj/chap03/se02/jjframe.htm";
    menu[9]="第一节  企业文化"; myurl[9]="../content/kcjj/chap04/se01/jjframe.htm";
    menu[10]="第二节 企业思想政治工作"; myurl[10]="../content/kcjj/chap04/se02/jjframe.htm";
    menu[11]="第一节 企业工资分配制度改革"; myurl[11]="../content/kcjj/chap05/se01/jjframe.htm";
    menu[12]="第二节 工资制度的内容与类型"; myurl[12]="../content/kcjj/chap05/se02/jjframe.htm";
    menu[13]="第三节 工资形式"; myurl[13]="../content/kcjj/chap05/se03/jjframe.htm";
    menu[14]="第四节 职工福利和劳动保险"; myurl[14]="../content/kcjj/chap05/se04/jjframe.htm";
    menu[15]="第一节 经营战略的特点和重要性"; myurl[15]="../content/kcjj/chap06/se01/jjframe.htm";
    menu[16]="第二节 经营战略的关系、内容和体系"; myurl[16]="../content/kcjj/chap06/se02/jjframe.htm";
    menu[17]="第三节 经营战略管理"; myurl[17]="../content/kcjj/chap06/se03/jjframe.htm";
    menu[18]="第四节 经营战略的领导与组织"; myurl[18]="../content/kcjj/chap06/se04/jjframe.htm";
    menu[19]="第一节 外部环境一般内容的调研"; myurl[19]="../content/kcjj/chap07/se01/jjframe.htm";
    menu[20]="第二节 外部环境重点内容的调研"; myurl[20]="../content/kcjj/chap07/se02/jjframe.htm";
    menu[21]="第三节 企业内部条件分析"; myurl[21]="../content/kcjj/chap07/se03/jjframe.htm";
    menu[22]="第四节 战略综合分析"; myurl[22]="../content/kcjj/chap07/se04/jjframe.htm";
    function myselect(){
    cur_chaper=document.myoption.chaper.options.selectedIndex;
    cur_sel=0;
    num_sel=document.myoption.chaper.options[cur_chaper].value;
    for(i=0;i<cur_chaper;i++)
    cur_sel=cur_sel+parseInt(document.myoption.chaper.options[i].value);
    if(cur_sel=="") cur_sel=0;
    document.myoption.select.length=parseInt(num_sel);
    counti=0;
    for(i=cur_sel;i<parseInt(cur_sel)+parseInt(num_sel);i++)
    {
    document.myoption.select.options[counti].text=menu[i];
    document.myoption.select.options[counti].value=i;
    counti=counti+1;
    }
    document.myoption.select.options.selectedIndex=0;
    }function MM_goToURL() { //v3.0
      var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
      for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }function gotoselect(){
    temp=document.myoption.select.options.selectedIndex;
    mysel=document.myoption.select.options[temp].value;
    mysel=parseInt(mysel);
    if(myurl[mysel].length>0)
    {
    MM_goToURL('parent.frames[\'abc\']',myurl[mysel]);
    return document.MM_returnValue;
    }
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    .chaper {  font-family: "宋体", "隶书"; font-size: 14px; font-style: normal; line-height: 18px; color: #006666; background-color: #FFFFFF}
    -->
    </style>
    </head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" onLoad="">
    <form name="myoption">
      <table border=0 cellpadding=0 cellspacing=0 width="800" height="29">
        <tr> 
          <td colspan="2"> 
            <select name="chaper" class="chaper" onChange="myselect();">
              <option value="3" selected>第一章 企业</option>
              <option value="4">第二章 企业管理综述</option>
              <option value="2">第三章 企业的领导体制和组织机构</option>
              <option value="2">第四章 企业文化与思想政治工作</option>
              <option value="4">第五章 工资分配</option>
              <option value="4">第六章 企业经营战略概述</option>
              <option value="4">第七章 企业战略环境的调查与分析</option>
            </select>
            <select name="select" class="chaper">
              <option value=0 selected>第一节 企业及其类型</option>
              <option value=1 >第二节 企业经营方式</option>
              <option value=2 >第三节 企业组织形式</option>
            </select>
          </td>
        </tr>
      </table>
    </form>
    </body>
    </html>:_)
      

  3.   

    Try:
    <html>
    <head>
    <script languang="javascript">
    function mm()
    {
        var car=new Array(3);
        var flower=new Array(3);
        var fruit=new Array(3);
        var i;
        
        car[0]="宝马";
        car[1]="奔驰";
        car[2]="东风";
        flower[0]="玫瑰";
        flower[1]="康乃馨";
        flower[2]="菊花";
        fruit[0]="banana";
        fruit[1]="orange";
        fruit[2]="apple";
      
        while(s2.options.length != 0)
             s2.remove(0);
       
        if(s1.selectedIndex == 0)
    for(i=0;i<fruit.length;i++)
                s2.options.add(new Option(fruit[i],i));
           
        
        else if(s1.selectedIndex == 1)
    for(i=0;i<flower.length;i++)
                s2.options.add(new Option(flower[i],i));
        
        if(s1.selectedIndex == 2)
    for(i=0;i<car.length;i++)
          s2.options.add(new Option(car[i],i));
    }
    </script>
    </head>
    <body>
    <select onChange=mm() name="s1">
    <option value=1>水果
    <option value=2>花卉
    <option value=3>汽车
    </select>
    <select name="s2">
    </select>
    </body>
    </html>
      

  4.   

    请问二级菜单的value是多少呢?比如wssgwps(小刀会) 的这个例子里。谢谢!