小程序开发中,使用textarea如何显示实时的字数:
WXML
<view>
<view>
<textarea name="content" bindinput="bindTextAreaChange" maxlength="{{noteMaxLen}}" />
<view class="chnumber">{{noteNowLen}}/{{noteMaxLen}}view>
view>
view>
JS
<view>
<view>
<textarea name="content" bindinput="bindTextAreaChange" maxlength="{{noteMaxLen}}" />
<view class="chnumber">{{noteNowLen}}/{{noteMaxLen}}view>
view>
view>
回答
小泽回答
在JS中加入如下代码:
//字数改变触发事件
bindTextAreaChange: function (e) {
var that = this
var value = e.detail.value,
len = parseInt(value.length);
if (len > that.data.noteMaxLen)
return;
that.setData({
content: value, noteNowLen: len
})
},
(0)