【问题标题】:Twitter-like Textbox Character Count with inline alert带有内联警报的类似 Twitter 的文本框字符计数
【发布时间】:2011-09-23 13:35:23
【问题描述】:

我想要一个文本框字符“向上计数”,它会在用户键入时增加计数,并在用户越过所需字符但仍允许用户继续键入时显示文本警报。

【问题讨论】:

    标签: jquery count textarea character


    【解决方案1】:

    如果你想自己动手

    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()
        }
    });
    

    JSFiddle here

    【讨论】:

    • 嗨 njreed,这就是帮助。稍微修改了一下,得到了这个jsfiddle.net/xVsUe,它非常适合我的需要。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 2018-06-03
      • 1970-01-01
      • 2013-03-31
      相关资源
      最近更新 更多