This article mainly introduces the implementation code for dynamically modifying the style of WeChat applet JS. The principle is to bind data and then dynamically modify the data to achieve dynamic style changes. Friends in need can refer to it
The pitfall of the WeChat applet is that js can dynamically modify the style. We cannot easily use js or jq to do it with one line of code. Or use removeClass addClass to modify the style.
The following is a method of dynamically modifying styles. The principle is to bind data and then dynamically modify the data to achieve dynamic style changes. It feels a bit... that kind of thing, weird. But there was nothing we could do. If you have a better method, you can share it in the comment area.
test.wxml
<view style="text-align: center;"> <label style="color:{{color}};">我会变色</label> <button bindtap="clickRed">变红</button> <button bindtap="clickgreen">变绿</button> </view>
test.js
Page({ data: { color: "red" }, clickRed: function () { this.setData({ color: "red" }) }, clickgreen: function () { this.setData({ color: "green" }) } })
Effect
How to call global JS in WeChat development?
2.Detailed explanation of examples of referencing other js files in WeChat development
3.Example tutorial of life cycle functions in WeChat development
The above is the detailed content of WeChat development JS dynamic modification style. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor