<view class='ul'>
<view class='u_1' bindtap='jian'>-</view>
<input type='digit' placeholder='{{yemian.num_t}}' value='{{yemian.num}}' bindfocus='focus' bindblur='blur'></input>
<view class='u_2' bindtap='jia'>+</view>
</view>
Page({
data: {
yemian: {
num: '0',
num_t: '',
}
},
onLoad: function() {},
//加操作
jia: function () {
var that = this;
var yemian = that.data.yemian;
if (yemian.num == '') {
yemian.num = yemian.num_t;
}
yemian.num = (parseInt(yemian.num) + 1).toString();
that.setData({
yemian: yemian,
});
},
//减操作
jian: function () {
var that = this;
var yemian = that.data.yemian;
if (yemian.num == '0') return;
yemian.num = (parseInt(yemian.num) - 1).toString();
that.setData({
yemian: yemian,
});
},
///获取焦点事件
focus: function (e) {
var that = this;
var yemian = that.data.yemian;
yemian.num_t = yemian.num;
yemian.num = '';
that.setData({
yemian: yemian
});
},
//失去焦点事件
blur: function (e) {
var that = this;
var yemian = that.data.yemian;
if (e.detail.value == '') {
yemian.num = yemian.num_t;
} else {
yemian.num = e.detail.value.toString()
}
that.setData({
yemian: yemian
});
}
})
当input焦点未离开input时,点击+(view),理想值是101,但实际是100,如果仔细看的话应该是101瞬间变为100,
附加问题:
yemian.num = 200;
yemian.num_t = yemian.num;
改 yemian.num = 0;
yemian.num_t 的值也随之改为0
为什么??????
你这个函数影响了,在你点击+-的时候,会同时执行这里面的函数导致的
谢谢,问题确实出在这, 那请问下, 有没有什么办法可以点击+-的时候,先让input失去焦点再去操作点击事件
做个开关判断试下?