<script>$(function(){$('#comments_content').bind('input propertychange', function () {var fizeNum = $(this).val().length;//获取输入字数if (fizeNum > 500) {//如果大于500var char = $(this).val();char = char.substr(0, 500);//截取字符串(前500)$(this).val(char);fizeNum = 500;}$(this).parent().find('.textNum').text(fizeNum);});))</script><div class="form-group"><label class="col-sm-3 control-label" for="comments_content">评论内容:</label><div class="col-sm-6"><textarea name="comments_content" id="comments_content" class="form-control limited" rows="8" maxlength="500" placeholder="请输入评论内容"></textarea><div class="text-right"><span class="textNum">0</span>/500</div></div></div><div id="app"><textarea v-model:trim="formobj.content" @input="descInput" maxlength="500" placeholder="请在此输入......" ></textarea>{{txtVal}}/500</div><script>var vm = new Vue({el : "#app",data : {formobj : {content : ""},txtVal : 0},methods : {descInput : function() {this.txtVal = this.formobj.content.length;},}});</script>
1200字范文,内容丰富有趣,写作的好帮手!