当前位置:网站首页>mui中使用多级选择器实现省市区联动
mui中使用多级选择器实现省市区联动
2022-08-02 16:59:00 【zh3210576】
mui中使用多级选择器实现省市区联动
1.环境配置
需要在项目中引入额外的js与css文件,分别是选择器的mui.picker.min.css、mui.picker.min.js与全国地区的数据文件city.data-3.js
其中city.data-3.js文件主要为全国省市区数据信息
其中我们在页面中只需要使用cityData3对象名,至于内部数据我们不需要考虑。
在页面中需要导入js、css文件,需要注意的是,mui.picker.min.js文件要在mui.js后面导入
2.布局部分
设置页面元素的事件监听,当点击input时初始化picker选择器对象
具体代码如下
<div class="mui-input-row">
<label>省市区</label>
<input type="text" placeholder=">" id="sel4" readonly style="text-align: right;"/>
</div>
3.JS部分
通过页面元素id对页面元素做tap监听,并且在确认选项后,将选择的数据显示在页面元素中
document.getElementById("sel4").addEventListener("tap",function(){
var myPicker = new mui.PopPicker({
layer:3
});
myPicker.setData(cityData3);
myPicker.show(function(e){
document.getElementById("sel4").value=e[0].text+" "+e[1].text+" "+e[2].text;
});
});在这里插入代码片
设置选择器层级,绑定数据源,将选择器选中的每层数据显示出来
点击确定后界面
边栏推荐
- 文件上传很难搞?10分钟带你学会阿里云OSS对象存储
- Mysql——字符串函数
- golang源码阅读(11)GO中各个目录的功能
- RAID存储级别分类
- [300+ selected big factory interview questions continue to share] Big data operation and maintenance sharp knife interview questions column (10)
- 阿里云关系型数据库RDS是干嘛额?
- 【无标题】
- 乌总统解除乌克兰国家安全局信息和情报分析部负责人职务
- Kubernetes:(七)优化大法(江湖失传已久的武林秘籍)
- Mysql应用安装后找不到my.ini文件
猜你喜欢
随机推荐
navicat创建连接 2002-can‘t connect to server on localhost(10061)且mysql服务已启动问题
Five speakers: seventy genius_platform software platform development 】 【 turn YUY2 RGB24 implementation source code
实时数仓架构演进及选型
LeetCode·76.最小覆盖子串·滑动窗口
启航
每日优鲜倒了,叮咚买菜的春天在哪?
Common software silent installation parameters
NoSQL之redis缓存雪崩、穿透、击穿概念解决办法
Summary of CNN classic models [easy to understand]
Nacos的基本配置
Real-time data warehouse architecture evolution and selection
golang源码分析(5):sync.Once
分类实验报告作业
nacos简单使用
内网渗透之kerberos认证(三)
Mysql应用安装后找不到my.ini文件
小心 transmittable-thread-local 的这个坑
Detailed explanation of the principle of JWT_The principle of electromagnetic induction
持续集成(四)Jenkins配置报警机制
谁抢走了华大基因的生意?