Home > WeChat Applet > Mini Program Development > How to use js to modify css in a small program

How to use js to modify css in a small program

coldplay.xixi
Release: 2023-01-04 09:37:40
Original
8157 people have browsed it

The small program uses js to modify css: first, the page dynamically binds the style variables; then initializes the variables in the data object; then assigns values ​​to the life cycle function variables; finally, save the code on the left side to view the effect.

How to use js to modify css in a small program

The operating environment of this article: Windows 7 system, WeChat applet development tool 2019 version, Dell G3 computer.

Related free recommendations: 小program development tutorial

How to use js to modify css in a small program:

1. Open the WeChat applet development tool, create a new wxml file, add views and buttons, set styles and bind font color variables

How to use js to modify css in a small program

2. Open the js file of the corresponding page and initialize the variable color in the data object

How to use js to modify css in a small program

3. In the life cycle function onLoad, use this.setData( {color:'#000'})

How to use js to modify css in a small program

4. Save the code and refresh, check the corresponding page module of the simulator on the left, and see that the button font color is black

How to use js to modify css in a small program

5. In the page code style, add font-size and bind the variable fontSize

How to use js to modify css in a small program

6. Then initialize the variable fontSize in the data object, and then assign a value to fontSize in onLoad

How to use js to modify css in a small program

7. Save the code again and check the simulator on the left. You can see that the font size has become larger.

How to use js to modify css in a small program

The above is the detailed content of How to use js to modify css in a small program. 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template