<select name=one></select>
<select name=two></select>
<select name=three></select>
<select name=four></select>
<input name=result><script>
var arrSel=["one","two","three","four"];//arrSel定义了要修改的下拉框
var i=0,arrData=[];//arrData中搁的是数据,每条都显示各级的数据
arrData[i++]=["2000","4","14","一点"]
arrData[i++]=["2000","4","14","二点"]
arrData[i++]=["2000","4","18","三点"]
arrData[i++]=["2000","7","14","二点"]
arrData[i++]=["2001","6","15","二点"]
arrData[i++]=["2001","6","23","七点"]
arrData[i++]=["2001","8","18","二点"]
arrData[i++]=["2002","7","1","二点"]
arrData[i++]=["2002","7","1","三点"]
arrData[i++]=["2002","7","11","二点"]
arrData[i++]=["2002","7","19","二点"]
</script>
<script>
function qswhInit(num){
/******* by qiushuiwuhen(2002-5-15) ********/
    var i,j,arrTemp=[];
    for(i=0;i<num;i++)arrTemp[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].text
    if(num==arrSel.length){//这里处理最后的数据。
        document.all("result").value="选中了("+arrTemp[0]+","+arrTemp[1]+","+arrTemp[2]+","+arrTemp[3]+")";return;
    }
    with(document.all(arrSel[num])){
        length=0
        for(i=0;i<arrData.length;i++){        
            for(j=0;j<num;j++)if(arrTemp[j]!=arrData[i][j])break;
            if(j!=num)continue;
            if(length==0||options[length-1].text!=arrData[i][num])
            options[length++].text=arrData[i][num];
        }
        onchange=new Function("qswhInit("+(num+1)+")");
        onchange();
    }
}
qswhInit(0);//初始化
</script>
<select name=year></select>
<select name=month></select>
<select name=date></select>
<select name=clock></select>
<input name=result><script>
var arrSel=["year","month","date","clock"];//arrSel定义了要修改的下拉框和xml数据的节点名称
</script><xml id=xmldata>
    <xmldata>
        <year value="2000">
            <month value="4">
                <date value="14">
                    <clock value="一点" />
                    <clock value="三点" />
                </date>
                <date value="17">
                    <clock value="一点" />
                </date>
            </month>
            <month value="5">
                <date value="15">
                    <clock value="一点" />
                    <clock value="四点" />
                    <clock value="七点" />
                </date>
            </month>
        </year>
        <year value="2001">
            <month value="7">
                <date value="16">
                    <clock value="一点" />
                    <clock value="五点" />
                    <clock value="九点" />
                </date>
            </month>
        </year>
    </xmldata>
</xml><script>
function qswhXml(num){
/******* by qiushuiwuhen(2002-5-17) ********/
    var i,j,arrTemp=[];
    for(i=0;i<num;i++)arrTemp[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].text
    if(num==arrSel.length){//这里处理最后的数据。
        document.all("result").value="选中了("+arrTemp+")";return;
    }
    with(document.all(arrSel[num])){
        length=0
        var obj=document.all.xmldata.XMLDocument.childNodes[0];
        for(i=0;i<num;i++)obj=obj.selectSingleNode(arrSel[i]+'[@value="'+arrTemp[i]+'"]');
        for(i=0;i<obj.childNodes.length;i++)options[length++].text=obj.childNodes[i].getAttribute("value");
        onchange=new Function("qswhXml("+(num+1)+")");
        onchange();
    }
}
qswhXml(0);
</script>

解决方案 »

  1.   

    如何实现这样的功能??用户在登记个人的籍贯时,不用手输,而是在文本框上单击后,弹出一个小窗口,在其中选择其籍贯(行政区划),选好后,关闭此窗口,并且将选择的结果返回到原来的窗口中????谢谢了,能实现不?test.htm
    <!-- STEP TWO: Paste this code into the HEAD of your HTML document  -->
    <html>
    <HEAD><SCRIPT LANGUAGE="JavaScript">
    <!-- Original:  Pankaj Mittal ([email protected]) -->
    <!-- Web Site:  http://www.fortunecity.com/lavendar/lavender/21 --><!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com --><!-- Begin
    function small_window(myurl) {
    var newWindow;
    var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=300,height=200';
    newWindow = window.open(myurl, "Add_from_Src_to_Dest", props);
    }
    // Adds the list of selected items selected in the child
    // window to its list. It is called by child window to do so.  
    function addToParentList(sourceList) {
    destinationList = window.document.forms[0].parentList;
    for(var count = destinationList.options.length - 1; count >= 0; count--) {
    destinationList.options[count] = null;
    }
    for(var i = 0; i < sourceList.options.length; i++) {
    if (sourceList.options[i] != null)
    destinationList.options[i] = new Option(sourceList.options[i].text, sourceList.options[i].value );
       }
    }
    // Marks all the items as selected for the submit button.  
    function selectList(sourceList) {
    sourceList = window.document.forms[0].parentList;
    for(var i = 0; i < sourceList.options.length; i++) {
    if (sourceList.options[i] != null)
    sourceList.options[i].selected = true;
    }
    return true;
    }// Deletes the selected items of supplied list.
    function deleteSelectedItemsFromList(sourceList) {
    var maxCnt = sourceList.options.length;
    for(var i = maxCnt - 1; i >= 0; i--) {
    if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) {
    sourceList.options[i] = null;
          }
       }
    }
    //  End -->
    </script>
    </HEAD><!-- STEP TWO: Copy this code into the BODY of your HTML document  --><BODY><center>
    <form method=post>
    <table border=1 bgcolor="#ffffcc">
    <tr>
    <td>
    <select size=5 name=parentList multiple>
    </select>
    <input type=text name=parentList multiple>
    </td>
    </tr>
    <tr>
    <td align=center>
    <input type=button value="Add Item" onclick = "javascript:small_window('modify.html');">
    <input type=button value="Delete Item" onclick = "javascript:deleteSelectedItemsFromList(parentList);">
    </td>
    </tr>
    </table>
    </form>
    </center><p><center>
    <font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
    by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
    </center><p>
    </html>
    <!-- Script Size:  5.27 KB -->modify.htm 弹出的页面
    <html>
    <head>
    <script language="JavaScript"><!--
    // Add the selected items in the parent by calling method of parent
    function addSelectedItemsToParent() {
    self.opener.addToParentList(window.document.forms[0].destList);
    window.close();
    }
    // Fill the selcted item list with the items already present in parent.
    function fillInitialDestList() {
    var destList = window.document.forms[0].destList; 
    var srcList = self.opener.window.document.forms[0].parentList;
    for (var count = destList.options.length - 1; count >= 0; count--) {
    destList.options[count] = null;
    }
    for(var i = 0; i < srcList.options.length; i++) { 
    if (srcList.options[i] != null)
    destList.options[i] = new Option(srcList.options[i].text);
       }
    }
    // Add the selected items from the source to destination list
    function addSrcToDestList() {
    destList = window.document.forms[0].destList;
    srcList = window.document.forms[0].srcList; 
    var len = destList.length;
    for(var i = 0; i < srcList.length; i++) {
    if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
    //Check if this value already exist in the destList or not
    //if not then add it otherwise do not add it.
    var found = false;
    for(var count = 0; count < len; count++) {
    if (destList.options[count] != null) {
    if (srcList.options[i].text == destList.options[count].text) {
    found = true;
    break;
          }
       }
    }
    if (found != true) {
    destList.options[len] = new Option(srcList.options[i].text); 
    len++;
             }
          }
       }
    }
    // Deletes from the destination list.
    function deleteFromDestList() {
    var destList  = window.document.forms[0].destList;
    var len = destList.options.length;
    for(var i = (len-1); i >= 0; i--) {
    if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
    destList.options[i] = null;
          }
       }
    }
    // End -->
    </SCRIPT>
    </head>
    <body onLoad="javascript:fillInitialDestList();">
    <center>
    <form method="POST">
    <table bgcolor="#FFFFCC">
    <tr>
    <td bgcolor="#FFFFCC" width="74">Available</td>
    <td bgcolor="#FFFFCC"> </td>
    <td bgcolor="#FFFFCC" width="69">Selected</td>
    </tr>
    <tr>
    <td bgcolor="#FFFFCC" width="85">
    <select size="6" name="srcList" multiple>
    <option value="1">Item 1
    <option value="2">Item 2
    <option value="3">Item 3
    <option value="4">Item 4
    <option value="5">Item 5
    <option value="6">Item 6
    </select>
    </td>
    <td bgcolor="#FFFFCC" width="74" align="center">
    <input type="button" value=" >> " onClick="javascript:addSrcToDestList()">
    <br><br>
    <input type="button" value=" << " onclick="javascript:deleteFromDestList();">
    </td>
    <td bgcolor="#FFFFCC" width="69">
    <select size="6" name="destList" multiple>
    </select>
    <input type="text" name=" destList" multiple >
    </td>
    </tr>
    <tr>
    <td colspan=3 align="center">
    <input type="button" value="Done" onClick = "javascript:addSelectedItemsToParent()">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>