您的位置:首頁技術文章
文章詳情頁

javascript - 可輸入的div怎么限制輸入的字數

瀏覽:87日期:2022-12-09 11:16:29

問題描述

<p contenteditable='true'></p>

可輸入的p怎么限制輸入的字個數

問題解答

回答1:

<p contenteditable='true'>1</p>$ele.onkeyup = function(){ var _html = this.innerHTML; if(_html.length > 10){ this.innerHTML = _html.substr(0,10); this.blur(); }}回答2:

設置innerHTML.length=“字符個數”

回答3:

通過js來限制,參考: http://stackoverflow.com/ques...

回答4:

<p contenteditable='true'></p> <script type='text/javascript'> document.querySelector(’#test’).addEventListener(’keypress’,function(e) { if(this.innerText.length>=10) {e.preventDefault(); } }); </script>

標簽: JavaScript
相關文章:
国产综合久久一区二区三区