Because IE does not support textarea maxlength properties, the test in Firefox 6 shows that Firefox supports this attribute. So it's easy. Write yourself a jquery extension so it's easy to implement the maximum length for textarea control.
(function ($) {
$.fn.textarealimit = function (settings) {
Settings = Jquery.extend ({
length:1000
}, settings);
MaxLength =settings.length;
$ (this). attr ("MaxLength", maxlength). Bind ("KeyDown", Dokeydown). Bind ("KeyPress", dokeypress). Bind ("Beforepaste", Dobeforepaste). Bind ("Paste", dopaste);
function dokeypress ()
{
var OTR = Document.selection.createRange ()
if (oTR.text.length >= 1)
Event.returnvalue = True
else if (This.value.length > MaxLength-1)
Event.returnvalue = False
}
function Dokeydown ()
{
var _obj=this;
settimeout (function ()
{
if (_obj.value.length > MaxLength-1)
{
var OTR = Window.document.selection.createRange ()
Otr.movestart ("character", -1* (_obj.value.length-maxlength))
Otr.text = ""
}
},1)
}
function Dobeforepaste ()
{
Event.returnvalue = False
}
function Dopaste ()
{
Event.returnvalue = False
var OTR = Document.selection.createRange ()
var iinsertlength = maxlength-this.value.length + oTR.text.length
var sData = window.clipboardData.getData ("Text"). substr (0, Iinsertlength)
Otr.text = SData;
}
}
}) (JQuery);
Above only for IE control copy and paste control and input control, because of the use of IE characteristics, these methods in Firefox is ineffective.
Calling code:
$ (document). Ready (function () {
$ ("#ctl00_ZiiOContent_ucQuestionnaire_txtquestion4_2"). Textarealimit ();
});