以限制100字以内为例
HTML:
<textarea value="{{introduce}}" maxlength="100" name="textarea" bindinput='limitWord'>
</textarea>
<view class="wordNum">({{currentWord}}/100)</view>
JS:
data: {
currentWord: 0,
introduce:"这边是显示的文字",
},
onLoad: function (options) {
this.setData({
currentWord: this.data.introduce.length
});
},
limitWord: function (e) {
var that = this;
var value = e.detail.value;
var wordLength = parseInt(value.length);
if (100 < wordLength) {
return;
}
that.setData({
currentWord: wordLength
});
},