【问题标题】:How to put a text limit in a form input box如何在表单输入框中设置文本限制
【发布时间】:2017-03-09 09:08:47
【问题描述】:

我希望对表单的输入框设置字符限制。理想情况下,我想要 140 个字符,但不知道该怎么做。

我在前端使用 Angular。

我的输入部分代码我需要 new.html 的文本限制

<div class="form-group">
  <label>Description 140 characters</label>
  <input type="text" ng-model="postsNew.post.description" class="form-control"  </textarea> 

我尝试使用另一种 textarea 方式,但它删除了我的一半表单。

这是我本节的完整代码

<section class="container">
    <h1>What happened?</h1>
    <form ng-submit="postsNew.submit()">
        <div class="form-group">
            <label>Tube Line</label>
            <select ng-model="postsNew.post.line" class="form-control">
                <option ng-repeat="line in postsNew.linesList" value="{{line}}">
                    {{line}}
                </option>
            </select>
        </div>
        **
        <div class="form-group">
            <label>Description 140 characters</label>
            <input type="text" ng-model="postsNew.post.description"
                   class="form-control"  </textarea>
        </div>
        **
        <div class="form-group">
            <label>Date</label><br>
            <input id="enddatefield" type="date" ng-model="postsNew.post.date"
                   class="form-control">
        </div>
        <div class="form-group">
            <label>Time</label><br>
            <input type="time" name="name" ng-model="postsNew.post.time"
                   class="form-control">
        </div>
        <input type="submit" value="Fingers crossed..." class="btn btn-primary
     pull-right">
    </form>
</section>

【问题讨论】:

    标签: javascript jquery html angularjs


    【解决方案1】:

    maxlength="int"

    示例:

    <input type="text" name="text" maxlength="10">
    

    工作DEMO

    【讨论】:

      【解决方案2】:
      <input type="text" ng-model="postsNew.post.description" class="form-control" maxlength="140" />
      

      【讨论】:

        【解决方案3】:

        您可以在输入字段中使用此maxlength="140" 属性。

        【讨论】:

          【解决方案4】:

          您可以使用 ma​​xlength

          <input type="text" name="max_length" maxlength="20">
          

          【讨论】:

            猜你喜欢
            • 2010-11-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-09-06
            • 2011-06-17
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多