【发布时间】:2011-09-23 13:35:23
【问题描述】:
我想要一个文本框字符“向上计数”,它会在用户键入时增加计数,并在用户越过所需字符但仍允许用户继续键入时显示文本警报。
【问题讨论】:
标签: jquery count textarea character
我想要一个文本框字符“向上计数”,它会在用户键入时增加计数,并在用户越过所需字符但仍允许用户继续键入时显示文本警报。
【问题讨论】:
标签: jquery count textarea character
如果你想自己动手
HTML
<div>
Type text here:
<input type="text" id="txt" />
</div>
<div id="warning" style="color: red; display: none">
Sorry, too much text.
</div>
<br>
<input type="text" id="counter" disabled="disabled" value="0"/>
脚本
$("#txt").keyup(function () {
var i = $("#txt").val().length;
$("#counter").val(i);
if (i > 10) {
$("#warning").show()
} else {
$("#warning").hide()
}
});
【讨论】:
【讨论】: