如何在表单输入框

时间:2016-10-26 20:43:20

标签: javascript jquery html 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> 

我尝试使用另一种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>

4 个答案:

答案 0 :(得分:5)

使用maxlength="int"

实施例

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

工作DEMO

答案 1 :(得分:4)

您可以使用 maxlength

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

答案 2 :(得分:3)

<input type="text" ng-model="postsNew.post.description" class="form-control" maxlength="140" />

答案 3 :(得分:2)

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