<script>
$(function(){
//先選出 textarea 和 統計字數 dom 節點
var wordCount = $("#wordCount"),
textArea = wordCount.find("textarea"),
word = wordCount.find(".word");
//調用
statInputNum(textArea,word);
});
/*
* 剩餘字數統計
* 注意 最大字數只需要在放數字的節點哪裏直接寫好即可 如:<var class="word">200</var>
*/
function statInputNum(textArea,numItem) {
var max = numItem.text(),
curLength;
textArea[0].setAttribute("maxlength", max);
curLength = textArea.val().length;
numItem.text(max - curLength);
textArea.on('input propertychange', function () {
numItem.text(max - $(this).val().length);
});
}
</script>
jquery判斷顯示剩下可輸入內容字數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.