文章詳情頁(yè)
javascript - 可輸入的div怎么限制輸入的字?jǐn)?shù)
瀏覽:114日期:2022-12-09 11:16:29
問(wèn)題描述
<p contenteditable='true'></p>
可輸入的p怎么限制輸入的字個(gè)數(shù)
問(wèn)題解答
回答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=“字符個(gè)數(shù)”
回答3:通過(guò)js來(lái)限制,參考: 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>
標(biāo)簽:
JavaScript
相關(guān)文章:
1. 關(guān)于docker下的nginx壓力測(cè)試2. nignx - docker內(nèi)nginx 80端口被占用3. docker-machine添加一個(gè)已有的docker主機(jī)問(wèn)題4. docker鏡像push報(bào)錯(cuò)5. python3.x - python連oanda的模擬交易api獲取json問(wèn)題第五問(wèn)6. angular.js - angular內(nèi)容過(guò)長(zhǎng)展開收起效果7. java - SSH框架中寫分頁(yè)時(shí)service層中不能注入分頁(yè)類8. node.js - 我是一個(gè)做前端的,求教如何學(xué)習(xí)vue,node等js引擎?9. 為什么我ping不通我的docker容器呢???10. html5 - 百度echart官網(wǎng)下載的地圖json數(shù)據(jù)亂碼
排行榜

熱門標(biāo)簽