jquery判断输入文字个数的统计代码

1、js代码部分

<script type=”text/javascript”>
$(function() {

function albumName() {
var text = $(“#album_name”).val();
var counter = text.length;
$(“#numtj var”).text(counter);
$(document).keyup(function() {
var text = $(“#album_name”).val();
var counter = text.length;
$(“#name_word”).text(counter);
});
}
});
</script>

 

2、html部分

<input type=”text” maxlength=”30″ name=”album_name” id=”album_name”>
<span><span id=”name_word”>0</span>/30</span>

 

3、贴张图看下效果

标签