asp.net copy tencent micro prompt can also enter * characters of the implementation code

  • 2020-05-16 06:40:43
  • OfStack

If textbox is set to TextMode="MultiLine", its MaxLength setting is invalid. In order to achieve like tencent meagre, weibo prompt effect (tencent and sina meager text box used should be textarea), try if you don't consider the content of the paste operation, using the mouse to delete textbox, with jquery keyup and keydown can realize, the following is a technique, use the js timer (when focus is "open" in textbox timer, loses focus is "closed" timer), very good solve the mouse operation paste, delete textbox content does not change the number of characters
Start by adding the following js code to the head tag
And, of course, jquery.js, if only I knew!
 
<script> 
var t = ""; 
function maxLimit() { 
if ($.trim($("#txtContent").val()).length > 140) { 
$("#txtleft").text(" Is beyond "); 
$("#LabelContent").text(($.trim($("#txtContent").val()).length) - 140); 
} 
else { 
$("#txtleft").text(" Can enter "); 
$("#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 the body edit
 
<div> <asp:TextBox ID="txtContent" runat="server" Width="500px" TextMode="MultiLine" MaxLength="140" 
Height="100px"></asp:TextBox></div> 
<div><span id="txtleft"> Can enter </span><asp:Label ID="LabelContent" runat="server" ForeColor="Red" 
Text="140"></asp:Label><span> A character </span></div> 

Related articles: