TextBox If you set Textmode= "MultiLine" the value of its maxlength setting is invalid; In order to achieve such as Tencent Meager, Sina meager such as the effect of the hint (Tencent and Sina meager text box should be used in the textarea), If you do not consider using the mouse to paste, delete the contents of the TextBox, with jquery KeyUp and KeyDown can be implemented, the following is a technique to implement, using the JS timer (when the focus in the TextBox is "open" timer, lost focus is "close" timer), A good solution to the mouse operation paste, delete the contents of the TextBox can not change the number of characters of the problem
First, add the following JS code to the head tag
Of course also to quote jquery.js, here to know the good!
Copy Code code as follows:
<script>
var t = "";
function Maxlimit () {
if ($.trim ("#txtContent"). Val ()). length > 140) {
$ ("#txtleft"). Text ("already exceeded");
$ ("#LabelContent"). Text (($.trim ($ ("#txtContent"). Val ()). Length)-140);
}
else {
$ ("#txtleft"). Text ("can also input");
$ ("#LabelContent"). Text (140-($.trim ($ ("#txtContent"). Val ()). length);
}
}
function Settimeouts () {
Maxlimit ();
t = settimeout ("Settimeouts ()", 1 * 10);
};
function Cleartimeouts () {
Cleartimeout (t);
};
$ (document). Ready (function () {
$ ("#txtContent"). KeyUp (Maxlimit);
$ ("#txtContent"). KeyDown (Maxlimit);
$ ("#txtContent"). Bind ("blur", cleartimeouts);
$ ("#txtContent"). Bind ("Focus", settimeouts)
});
</script>
Add in Body Edit
Copy Code code as follows:
<div> <asp:textbox id= "txtcontent" runat= "Server" width= "500px" textmode= "MultiLine" maxlength= "140"
height= "100px" ></asp:TextBox></div>
<div><span id= "Txtleft" > can also enter </span><asp:label id= "labelcontent" runat= "Server" ForeColor= "Red "
text= "140" ></asp:Label><span> characters </span></div>