微信小程序和普通的前端开发有很多不同.
前端开发中修改样式, 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 中修改的方法
来源: http://www.css88.com/qa/javascript/15589.html