熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

PHP網絡開發:動態列表框的實現[2]

2022-06-13   來源: PHP編程 
    ——此文章摘自《完全手冊PHP網絡開發詳解》定價 特價 詳細>>http://tracklinktechcn/?m_id=dangdang&a_id=A&l=&l_type= width= height= border= nosave>

    function RefreshCity()                      //主程序函數
    {
        CreateXMLHttpRequest();                 //創建對象
        xmlobjopen(GET geosxml true);   //調用XML
        xmlobjonreadystatechange = StatHandler;    //判斷URL調用的狀態值並處理
        xmlobjsend(null);                      //設置為不發送給服務器任何數據
    }
    function StatHandler()                      //用於處理狀態的函數
    {
        //如果URL成功訪問則輸出網頁
        if(xmlobjreadyState == && xmlobjstatus == && document getElementById(province)value != )  
        {
             var xml = xmlobjresponseXML;
             var province = documentgetElementById(province)value;
                                              //獲得用戶的當前選擇
             var currprov = xmlgetElementsByTagName(province)[];
                                             //獲得XML中的相應標簽
             var cities = currprovgetElementsByTagName(city);
                                                //獲得標簽下的所有city
             var citylist = documentgetElementById(citylist);
                                                //獲得頁面上的動態列表框
             while(citylistchildNodeslength > )                   //清空列表框
            {
                citylistremoveChild(citylistchildNodes[]);
            }
             for(var i = ; i < citieslength; i++)                  //插入全部標簽
             {
                 option = documentcreateElement(option);
                optionappendChild(documentcreateTextNode(cities[i]
                    childNodes[]nodeValue));
                citylistappendChild(option);
             }
        }
    }
    </script>
    </head>
    <body>
    <p><form action=>
    <p><select id=province onchange=RefreshCity();>
    <option value=>Select One</option>
    <option value=Beijing>Beijing</option>
    <option value=Liaoning>Liaoning</option>
    </select></p>
    <p><select id=citylist size= style=width:px;></select></p>
    </form></p>
    </body>
    </html>

    運行結果如圖所示

http://developcsaicn/web/images/jpg>
  動態列表框

right>[http://developcsaicn/web/htm>]  []  


From:http://tw.wingwit.com/Article/program/PHP/201311/21479.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.