Turn: jQuery control input of words

HTML content:

<input class="form-control" id="title" name="title" placeholder=" 请输入" type="text">

<span id="titleCount" style="color:#9B9B9B;text-decoration: none;font-size:12px;">还可以输入12个字</span>

  

JS content:

$("#titleCount").text("还可以输入" + (12 - $("#title").val().length) + "个字");
$("#title").keyup(function() {
    if ($("#title").val().length > 12) {
        $("#title").val($("#title").val().substring(0, 12));
    }
    $("#titleCount").text("还可以输入" + (12 - $("#title").val().length) + "个字");
}); 

Of course, to be introduced jquery file

 

Reprinted from: http://www.jq22.com/webqd4097

Guess you like

Origin www.cnblogs.com/fudanchencds/p/11113050.html