Twitter-like Textbox Character Count with inline alert

断了今生、忘了曾经 提交于 2019-12-04 09:46:44

If you want to roll your own

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"/>

Script

$("#txt").keyup(function () {
    var i = $("#txt").val().length;
    $("#counter").val(i);
    if (i > 10) {
        $("#warning").show()
    } else {
        $("#warning").hide()
    }
});

JSFiddle here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!