微信小程式 textarea 統計輸入長度
阿新 • • 發佈:2019-01-27
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">{{length}}/100</view> </view> </view> </view>
這裡要用bindinput
js
data: {
...
length: 0
},
//統計輸入長度 userInput: function(e) { console.log("輸入的內容---" + e.detail.value) console.log("輸入的長度---" + e.detail.value.length) this.setData({ length: e.detail.value.length }) },