如何在表单输入框中添加文本限制

nat*_*e87 0 html javascript jquery angularjs

我希望在表单上的输入框上添加字符限制.理想情况下我需要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> 
Run Code Online (Sandbox Code Playgroud)

我尝试使用另一种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>
Run Code Online (Sandbox Code Playgroud)

pao*_*sso 5

maxlength="int"

例:

<input type="text" name="text" maxlength="10">
Run Code Online (Sandbox Code Playgroud)

工作演示.