Based on jQuery + JSON, the provincial/municipal level-2 linkage effect,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.