微信小程序之Js修改元素样式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenbetter1996/article/details/82584866

微信小程序和普通的前端开发有很多不同。

后者修改样式js可以操作DOM,即 document.getElementById(id).style.property=new style

但是微信的js是没有DOM操作这功能的,也就没有  element.style.property=new style 这种方法(使用会报错,没定义)

正确方法:

<text style="color:{{color}}">变色</text>            元素样式使用内联式样式法,属性值使用微信提高的特殊表达式符合。

this.setData({ color: "green" })                这是js中修改的方法

猜你喜欢

转载自blog.csdn.net/chenbetter1996/article/details/82584866