在jQuery中限制textarea中的字符

在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.