页面加载如何调用点击事件
页面一加载想调用一个点击事件,苦思冥想不知道如何调用
页面一加载想调用一个点击事件,苦思冥想不知道如何调用
**
* 生命周期函数–监听页面加载
*/
onLoad: function (options) {
console.log(“页面加载开始。。。。。。。。。。”)
changeColor();
// this.data.txtArray[1].changeColor=true
},
changeColor: function (res) {
var txtArray = [];
for (var i = 0; i < this.data.txtArray.length; i++) {
if (res.target.id == this.data.txtArray[i].id) {
txtArray[i] = { id: this.data.txtArray[i].id, changeColor: true, txt: this.data.txtArray[i].txt }
console.log(“ture”)
} else {
txtArray[i] = { id: this.data.txtArray[i].id, changeColor: false, txt: this.data.txtArray[i].txt }
console.log(“false”)
}
}
this.setData({
txtArray: txtArray
})
},
报错:
changeColor is not defined;at pages/login/homePage page lifeCycleMethod onLoad function
ReferenceError: changeColor is not defined
手动执行执行changeColor这个函数,他的参数btn是undefined,不要直接使用res.target.id,发现是undefined可以先给一个默认值