简体   繁体   English

如何使正则表达式模式文本框中的装饰器无法选择?

[英]how to make the decorator in a regex pattern textbox unselectable?

here is a screenshot of regextester.com:这是 regextester.com 的屏幕截图: 在此处输入图片说明

users can only select the spaces between the preset pattern decorators, how to achieve this?用户只能选择预设图案装饰器之间的空间,如何实现? I inspected the stylesheets, still have no clue.我检查了样式表,仍然没有任何线索。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM