Home > Web Front-end > JS Tutorial > Use native js to realize three-level linkage between provinces and municipalities

Use native js to realize three-level linkage between provinces and municipalities

亚连
Release: 2018-06-06 10:09:36
Original
2795 people have browsed it

This article mainly introduces native js to realize the three-level linkage function of provinces and municipalities and code sharing. Friends in need can refer to it.

Preface

The plug-in functions only meet our company’s business needs. If you want more functions, you can leave a message below and I will try my best to expand! If you need or like it, you can give me a star on github

Preparation

<p id="wrap"></p>
Copy after login

The container tags in the page are not limited, just give an id

var address = new Address({
  wrapId: &#39;wrap&#39;,
  showArr: [&#39;provinces&#39;,&#39;citys&#39;,&#39;areas&#39;],
  beforeCreat:function(){
    console.log("beforeCreat")
  },
  afterCreat:function(){
    console.log(&#39;afterCreat&#39;);
  }
})
Copy after login
wrapId:"wrap" // 此处的wrap就是上面容器的id 
showArr: [&#39;provinces&#39;,&#39;citys&#39;,&#39;areas&#39;] // 此处分别代表省、市、区容器的id
Copy after login

For example: If the passed array ['provinces','citys','areas'] has a length of 3, then the provinces and cities will appear, with three characters in the array The strings are the ids of the province, city, and district containers respectively

For example, the passed array['provinces','citys'] has a length of 2, Then the province and city will appear. The two strings in the array are the IDs of the province and city containers respectively

If the array length is 1, we will not say it

beforeCreat The callback function executed before the plug-in is created

afterCreat The callback function executed after the plug-in is created

Preview

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

The problem of obtaining the upload size of path compressed image in Webpack (detailed tutorial)

Detailed interpretation in ES6 let and closure

Practical project in vue iview less echarts (detailed tutorial)

The above is the detailed content of Use native js to realize three-level linkage between provinces and municipalities. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template