[英]how to make the decorator in a regex pattern textbox unselectable?
You need to utilize contentEditable
, here's a simplified recreate of regextester input:您需要利用
contentEditable
,这里是regextester输入的简化重新创建:
document.querySelector('.editor').addEventListener('click', e => { e.currentTarget.querySelector('.input').focus(); });
.editor .input { outline: none; } .editor *:not(.input) { opacity: 0.5; user-select: none; }
<div class="editor"> <span>/</span> <span class="input" contentEditable="true"></span> <span>/g</span> </div>
Using pseudo elements is also a good idea since there are natually unselectable:使用伪元素也是一个好主意,因为它们自然是不可选择的:
document.querySelector('.editor').addEventListener('click', e => { e.currentTarget.querySelector('.input').focus(); });
.editor .input { outline: none; } .editor .input::before, .editor .input::after { opacity: 0.5; } .editor .input::before { content: '/'; } .editor .input::after { content: '/g'; }
<div class="editor"> <span class="input" contentEditable="true"> </span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.