With. NET control for a long time, in a page to increase the control length of the textbox, simply add a maxlength= ' xxx ' on the line, but the test is always the reason is set a multiline mode, in which case the generated HTML code is textarea, At the same time, the MaxLength attribute is not added because IE does not support textarea's maxlength attribute, so 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.
The extension code is as follows:
Copy Code code as follows:
(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:
Copy Code code as follows:
$ (document). Ready (function () {
$ ("#ctl00_ZiiOContent_ Ucquestionnaire_txtquestion4_2 "). Textarealimit ();
});