苒姐带我飞 2021-10-12 11:25 采纳率: 83.3%
浏览 49
已结题

微信小程序input,button设置整数乘法

img

  • 写回答

2条回答 默认 最新

  • Zarek⠀ 2021-10-12 17:15
    关注
    • 大概是这样子,一些小细节自己去改一下就好,有帮助麻烦点个采纳【本回答右上角】
    
    
    <input type="number" id="input1" bindinput="handleInput1" value="{{input1}}"/> *
    <input type="number" id="input2" bindinput="handleInput2" value="{{input2}}"/> =
    <button bindtap="calculate">计算</button>
    <view  id="result">
        <view wx:for="{{resultList}}">{{item}}</view>
    </view>
    
    
    
    
    Page({
      data: {
        result: [],
        input1: '',
        input2: '',
      },
      onLoad: function () {
        console.log('Welcome to Mini Code')
      },
      calculate: function () {
        const { input1, input2,resultList } = this.data
        if (input1 === '' || input2 === '') {
          wx.showToast({
            title: '请输入正确的数字',
            duration: 2000,
            icon: 'warning'
          });
        } else {
         resultList.push(`${input1} * ${input2} = ${input1 * 1 * input2}`)
        this.setData({
         resultList
        }, () => {
        wx.cloud.callFunction({
          name: 'result',
          data: resultList
        }).then(console.log)
    })
        }
      },
      handleInput1: function (e) {
        this.setData({
          input1: e.detail.value
        })
      },
      handleInput2: function (e) {
        this.setData({
          input2: e.detail.value
        })
      }
    })
    
    
    input {
      border: 1px solid;
      display: inline-block;
      width: 100pt;
    }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月12日
  • 已采纳回答 10月12日
  • 创建了问题 10月12日

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作