Jquery realize provinces linkage

<! DOCTYPE HTML>
<HTML>
    <head>
        <Meta charset = "UTF-. 8">
        <title> </ title>
        <Script type = "text / JavaScript" the src = "../ JS / jQuery-1.11.0 .js "> </ Script>
        <Script>
            var Provinces = [
                [" Shenzhen City, "" City, "" Huizhou City, "" Guangzhou "],
                [" Changsha City, "" Yueyang City, "" Zhuzhou City, "" Xiangtan City "],
                [" Xiamen "," Fuzhou "," Zhangzhou City, "" Quanzhou "]
            ];
            $ (function () {
                $ (" # Province ").Change (function () {
                    var = Provinces Cities [this.value];
                    // Clear select the city Option
                    / City * var = $ $ ( "# City");
                    // the object into a JS objects JQ
                    $ city.get citySelect = var (0)
                    citySelect.options.length = 0; * /
                    
                    $ ( "# City") empty ();. // clear manner using JQ
                    // iterate city data
                    $ (cities) .each (function (I, n-) {
                        $ ( "# City") the append ( "<Option>" + n-+ "</ Option>");.
                    });
                });
            });
            
            
            
        </ Script>
    </ head>
    <body>
        <-! select province ->
        <the sELECT the above mentioned id = "province">
            <the Option value = "- 1"> - Please select - </ the Option>
            <the Option value = "0"> Guangdong </option>
            <option value="1">湖南省</option>
            <option value="2">福建省</option>
        </select>
        <!--选择城市-->
        <select id="city">
            
        </select>
    </body>
</html>

<! - renderings ->

Published 21 original articles · won praise 7 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_40662239/article/details/89852064