博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序点击控件修改样式
阅读量:4230 次
发布时间:2019-05-26

本文共 684 字,大约阅读时间需要 2 分钟。

微信小程序中不支持直接操作dom,要实现这种效果,我们需要通过设置data,然后利用数据和界面的双向绑定来实现它。

第一步:在wxss中定义被点击和未被点击的样式,如下:

.service_selection .is_checked{    border: 1px solid #FE0002 ;    color: #FE0002 ;    background: #fff;  }  .service_selection .normal{    border: none;    color: #333;    background: #F0F1EC;  }

第二步:在js文件中的data中设置一个flag,叫他isChecked,默认isChecked==false。如下:

data: {      isChecked: false    }

第三步:在wxml文件中绑定点击事件,

在js文件中实现这个方法,并另他点击后设置isChecked==true。如下:

serviceSelection(){      this.setData({        isChecked:true      })  }

第四步:依然是在wxml文件中进行数据绑定:

重点是这一句代码

{
{
isChecked?'is_checked':'normal'}}"

这是一个三目运算符,当isChecked==true时,在class加上is_checked的样式,为flase时使用normal的样式。这一点的实现类似php控制样式类名的语法。

转载地址:http://hqjqi.baihongyu.com/

你可能感兴趣的文章
USB Mass Storage: Designing and Programming Devices and Embedded Hosts
查看>>
JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach
查看>>
From VBA to VSTO: Is Excel's New Engine Right for You?
查看>>
Sams Teach Yourself Data Structures and Algorithms in 24 Hours
查看>>
Professional Windows Desktop and Server Hardening
查看>>
Software Estimation: Demystifying the Black Art (Best Practices
查看>>
Handbook of Research on Mobile Multimedia
查看>>
SQLite (Developer's Library)
查看>>
Measuring Information Systems Delivery Quality
查看>>
Windows 2000 Performance Guide
查看>>
Ajax And Php: Building Responsive Web Applications
查看>>
ASP.NET 2.0 Website Programming: Problem - Design - Solution
查看>>
XML in a Nutshell, Third Edition
查看>>
Excel Programming Weekend Crash Course
查看>>
BigNum Math: Implementing Cryptographic Multiple Precision Arithmetic
查看>>
Computer Networks, Fourth Edition
查看>>
Great Ideas in Computer Science with Java
查看>>
Sams Teach Yourself Network Troubleshooting in 24 Hours (2nd Edition)
查看>>
Flash Enabled: Flash Design and Development for Devices
查看>>
The Tao of Network Security Monitoring: Beyond Intrusion Detection
查看>>