扫码关注官方订阅号
<p contenteditable="true"></p>
可输入的p怎么限制输入的字个数
<p contenteditable="true">1</p> $ele.onkeyup = function(){ var _html = this.innerHTML; if(_html.length > 10){ this.innerHTML = _html.substr(0,10); this.blur(); } }
设置innerHTML.length=“字符个数”
通过js来限制,参考: http://stackoverflow.com/ques...
<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>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
设置innerHTML.length=“字符个数”
通过js来限制,参考: http://stackoverflow.com/ques...