[英]Modify user selection on click event on an <a> element?
When I click on the text in the div element i am able to modify the selection.当我单击 div 元素中的文本时,我可以修改选择。 However this is not possible with a link element.但是,这对于链接元素是不可能的。 Is there a way I can make this work without modifying the html?有没有办法可以在不修改 html 的情况下完成这项工作?
document.addEventListener('click', click, true) function click(e) { e.preventDefault() } setInterval(() => { let selection = window.getSelection(); selection.modify('extend', 'forward', "documentboundary"); }, 100);
<div>text in div tag</div> <a href="">text in a tag</a>
Does this work?这行得通吗?
document.addEventListener('click', click, true) function click(e) { e.preventDefault() } setInterval(() => { let selection = window.getSelection(); selection.modify('extend', 'forward', "documentboundary"); }, 100);
a { user-select: text; }
<div>text in div tag</div> <a href="">text in a tag</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.