1 回答
TA贡献1831条经验 获得超10个赞
<view>
<input value='0' type="number" bindblur="inputB" data-iname='input1' ></input>
<input value='0' type="number" bindblur="inputB" data-iname='input2' ></input>
<input value='0' type="number" bindblur="inputB" data-iname='input3' ></input>
<input value='0' type="number" bindblur="inputB" data-iname='input4' ></input>
<button bindtap='cal'>总计</button> <text>{{count}}</text>
</view>
Page({
data: {
count:0,
all:{}
},
cal:function(){
var count = 0;
var all = this.data.all;
for(var i in all){
count += Number(all[i]);
}
this.setData({
count: count
});
console.log(this.data.count, count, all);
},
inputB:function(e){
var all = this.data.all;
var iname = e.target.dataset.iname;
all[iname] = e.detail.value;
this.setData({
all:all
});
},
onLoad: function () {
},
onReady:function(){
}
})
添加回答
举报