文章詳情頁
javascript - 可輸入的div怎么限制輸入的字數(shù)
瀏覽:85日期:2022-12-09 11:16:29
問題描述
<p contenteditable='true'></p>
可輸入的p怎么限制輸入的字個數(shù)
問題解答
回答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:
設(shè)置innerHTML.length=“字符個數(shù)”
回答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
相關(guān)文章:
1. Python如何播放還存在StringIO中的MP3?2. javascript - 請教如何獲取百度貼吧新增的兩個加密參數(shù)3. (python)關(guān)于如何做到按win+R再輸入文件文件名就可以運行?4. Python爬蟲如何爬取span和span中間的內(nèi)容并分別存入字典里?5. python - 編碼問題求助6. python - 關(guān)于計算日期的問題7. 網(wǎng)頁爬蟲 - Python 爬蟲中如何處理驗證碼?8. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處9. mysql 一個sql 返回多個總數(shù)10. mysql - 如何減少使用或者不用LEFT JOIN查詢?
排行榜

熱門標簽