我想限制 jquery 中文本中的字符。这是我的 jquery 代码
$('#editnote-tooltip-wrapper').appendTo($(this).closest('.editnote-tip-wrapper')).fadeIn(300).css({ 'position': 'absolute', 'left': 0, 'top': 0, 'z-index': '10000' }).find('.content').html('<textarea cols="5" rows="5" class="elastic" style="overflow: hidden; height: 150px;"></textarea>' + $html);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点。有人帮忙吗?
要限制字符,您可以使用html 的maxlength属性。喜欢<textarea cols="5" rows="5" class="elastic" style="overflow: hidden; height: 150px;" maxlength="500"></textarea>
无论如何,它在 ie9 中不起作用,但你可以按照下面的代码操作。
<form name="myform">
<textarea name="limitedtextarea" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,100);" onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,100);">
</textarea><br>
<font size="1">(Maximum characters: 100)<br>
You have <input readonly type="text" name="countdown" size="3" value="100"> characters left.</font>
</form>
Run Code Online (Sandbox Code Playgroud)
请参阅此页!了解更多信息。