input 组件foucs 和 blur 事件, view 组件的bindtap
发布于 6 年前 作者 xuetao 5844 次浏览 来自 问答

<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

        为什么??????

    

    

1 回复

你这个函数影响了,在你点击±的时候,会同时执行这里面的函数导致的

回到顶部