javascript - How to limit the number of words entered in an input div
为情所困
为情所困 2017-05-17 09:57:21
0
4
1209
<p contenteditable="true"></p>

How to limit the number of characters that can be entered

为情所困
为情所困

reply all(4)
曾经蜡笔没有小新
<p contenteditable="true">1</p>

$ele.onkeyup = function(){
  var _html = this.innerHTML;
  if(_html.length > 10){
    this.innerHTML = _html.substr(0,10);
    this.blur();
  }
}
左手右手慢动作

Set innerHTML.length="number of characters"

小葫芦

Restrict through js, refer to: http://stackoverflow.com/ques...

Peter_Zhu
  <p id="test" contenteditable="true"></p>
  <script type="text/javascript">
    document.querySelector('#test').addEventListener('keypress',function(e) {
      if(this.innerText.length>=10) {
        e.preventDefault();
      }
    });
  </script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template