asp.net imitation Tencent meager hint can also input * Character implementation code _ practical skills

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.