首先在head标记中添加如下js代码
当然还要引用jquery.js,这里知道就好了!
<script>
var t = "";
function maxLimit() {
if ($.trim($("#txtContent").val()).length > 140) {
$("#txtleft").text("已经超出");
$("#LabelContent").text(($.trim($("#txtContent").val()).length) - 140);
}
else {
$("#txtleft").text("还能输入");
$("#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>
在body编辑中添加
<div> <asp:TextBox ID="txtContent" runat="server" Width="500px" TextMode="MultiLine" MaxLength="140"
Height="100px"></asp:TextBox></div>
<div><span id="txtleft">还能输入</span><asp:Label ID="LabelContent" runat="server" ForeColor="Red"
Text="140"></asp:Label><span>个字符</span></div>