Based on jQuery + JSON, the provincial/municipal level-2 linkage effect,
The pull-down effect of provincial/municipal linkages is widely used in the WEB, especially in some member information systems and e-commerce websites. Developers generally use Ajax to implement a non-refreshing drop-down linkage. This article describes how to use the jQuery plug-in to read JSON data and achieve the linkage between the two (3) levels of cities and cities without refreshing data.
HTML
First, load the jquery library and cityselect plug-in the head.
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.cityselect.js"></script>
Next, we place three select statements in # city, and set the class attributes of the three select statements to prov, city, and dist, respectively, indicating the province, city, and district) three drop-down lists. Note: If you only want to implement provincial/municipal level-2 Association, remove the select statement of the third dist.
<div id="city"> <select class="prov"></select> <select class="city" disabled="disabled"></select> <select class="dist" disabled="disabled"></select> </div>
JQuery
Calling the cityselect plug-in is very simple and can be called directly:
$("#city").citySelect();
Custom parameter call, set the default province, city, and district.
$ ("# City "). citySelect ({url: "js/city. min. js ", prov:" Hunan ", // province city:" Changsha ", // city dist:" Yuelu district ", // district/county nodata: "none" // hide select} when the subset has no data });
Of course, you can also extend the custom drop-down list option data. You can set the drop-down content as needed. Note that the data format must be in JSON format.
$ ("# City "). citySelect ({url: {"citylist": [{"p": "frontend technology", "c": [{"n": "HTML "}, {"n": "CSS", "a": [{"s": "CSS2.0" },{ "s": "CSS3.0"}]}, {"n": "JAVASCIPT"}] },{ "p": "Programming Language", "c": [{"n": "C "}, {"n": "C ++" },{ "n": "PHP" },{ "n": "JAVA"}] },{ "p ": "Database", "c": [{"n": "Mysql" },{ "n": "SqlServer" },{ "n ": "Oracle"}]},]}, prov: "", city: "", dist: "", nodata: "none "});
You can also use PHP and other background languages to convert data in the database to JSON format, and then use the url parameter to point to the background address to achieve the effect of refreshing the link.
$("#city").citySelect({ url:"data.php" });
The above is all the content of this article. I hope you will like it.