收录日期:2020/10/28 10:50:32 时间:2010-09-07 02:29:49 标签:html,webforms,textbox,limit
<input type='text' name='one' id='oneID' maxlength="150"> 

i need the JS to display the number of characters left that user can input

alt text

a picture is worth a 1000 words so no more explanation required...

Bind a function to the onkeyup event that counts the number of characters entered and displays how much is remaining.

Example:

var e = document.getElementById('oneID'),
    f = document.getElementById('countDiv'); // some element where the count will be displayed

e.onkeyup = function() {
  f.innerHTML = (e.maxLength - e.value.length) + ' characters remaining';
}