收藏
回答

input 组件foucs 和 blur 事件, view 组件的bindtap

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug input 客户端 7.0.3 2.6.0

<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 个回答

登录 后发表内容