微信小程序 textarea 統計輸入長度

wxml

     <view class="weui-cells weui-cells_after-title">
          <view class="weui-cell">
               <view class="weui-cell__bd">
                    <textarea class="weui-textarea" placeholder="請輸入文本" style="height: 3.3em" maxlength='100' bindinput='userInput' />
                    <view class="weui-textarea-counter">{{num}}/100</view>
               </view>
          </view>
     </view>

這裏要用bindinput

js

     data: {
          ...
          num: 0
     },
     //統計輸入長度
     userInput: function(e) {
          console.log("輸入的內容---" + e.detail.value)
          console.log("輸入的長度---" + e.detail.cursor)
          this.setData({
               num: e.detail.cursor
          })
     },


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章