jquery implements secondary linkage drop-down selection based on layui

小云云
Release: 2018-01-06 11:29:36
Original
15260 people have browsed it

The drop-down selection function is very common to us. This article mainly introduces jquery to implement two-level linkage drop-down selection (province and city selection) based on layui. It has certain practical value. Friends who need it can refer to it. I hope it can help everyone.

Let’s take a look at the simple effect first

##Go directly to the code


html part (I took the value of the value in the drop-down box from the database)


Copy after login

js operation part


form.on('select(province)', function(data){ $.getJSON("/api/getCity?pid="+data.value, function(data){ var optionstring = ""; $.each(data.data, function(i,item){ optionstring += ""; }); $("#city").html('' + optionstring); form.render('select'); //这个很重要 }); });
Copy after login

The data format json returned by the background


{ "status": 200, "message": "result", "data": [ { "code": "3418", "name": "宣城市", "province": "34" }, { "code": "3417", "name": "池州市", "province": "34" }, { "code": "3416", "name": "亳州市", "province": "34" }, { "code": "3415", "name": "六安市", "province": "34" }, { "code": "3413", "name": "宿州市", "province": "34" }, { "code": "3412", "name": "阜阳市", "province": "34" }, { "code": "3411", "name": "滁州市", "province": "34" }, { "code": "3408", "name": "安庆市", "province": "34" }, { "code": "3407", "name": "铜陵市", "province": "34" }, { "code": "3406", "name": "淮北市", "province": "34" }, { "code": "3405", "name": "马鞍山市", "province": "34" }, { "code": "3404", "name": "淮南市", "province": "34" }, { "code": "3403", "name": "蚌埠市", "province": "34" }, { "code": "3402", "name": "芜湖市", "province": "34" }, { "code": "3401", "name": "合肥市", "province": "34" } ] }
Copy after login

Related recommendations:

Province and city level two implemented by AngularJS Linkage function example

jquery's ajax to achieve the second-level linkage effect implementation method

Realize the registration page jq second-level linkage

The above is the detailed content of jquery implements secondary linkage drop-down selection based on layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!