在jQuery中限制textarea中的字符 [英] Limit the Characters in textarea in jquery
本文介绍了在jQuery中限制textarea中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想限制jquery中textare中的字符.这是我的jquery代码
I want to Limit the characters in a textare in jquery .here is my jquery code
$('#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);
我怎样才能做到这一点.有人帮助吗?
how can I make this possible.anyone help?
推荐答案
可以使用html的 maxlength 属性来限制字符.就像<textarea cols="5" rows="5" class="elastic" style="overflow: hidden; height: 150px;" maxlength="500"></textarea>
to limit the character you can just use maxlength attribute of html. like <textarea cols="5" rows="5" class="elastic" style="overflow: hidden; height: 150px;" maxlength="500"></textarea>
无论如何它都无法在ie9中工作,但是您可以遵循以下代码.
anyhow it is not going to work in ie9 but you can follow the below code.
<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>
有关更多信息,请参见此页面!..
Refer this page!!. for more info.
这篇关于在jQuery中限制textarea中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文