收藏
回答

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

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
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


        为什么??????

    

    




最后一次编辑于  02-18  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员-白柿子
    社区技术运营专员-白柿子
    02-18

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

    02-18
    赞同
    回复 2
    • ㄨ℉ωιFι℅`
      ㄨ℉ωιFι℅`
      02-19

      谢谢,问题确实出在这,  那请问下, 有没有什么办法可以点击+-的时候,先让input失去焦点再去操作点击事件

      02-19
      回复
    • 社区技术运营专员-白柿子
      社区技术运营专员-白柿子
      02-19回复ㄨ℉ωιFι℅`

      做个开关判断试下?

      02-19
      回复