防止输入之间的拖动文本选择



我已经在最新的Chrome和IE11中对此进行了测试。

可以在输入中选择一个文本,然后至少在IE11和Chrome中将其拖动到另一个输入中。

我想预防。

我发现了许多示例/教程,显示了如何在如何实现拖放的示例中防止相反的示例:允许拖动,同时防止文本选择。

,但我想允许在鼠标拖动上选择文本 - 但请防止所选文本可拖动。

设置CSS属性-Webkit-user-Drag:无;还可以防止文本选择,我本来可以预期的属性:-webkit-user-select:auto;将控制预防文本选择。

这是一个jsfiddle:https://jsfiddle.net/9g419erc/

input {
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-user-drag: none;
}
<article>
    <input type="text" placeholder="Write text, select it, and drag">
    <input type="text" placeholder="Then drop text here">
</article>

仅使用CSS3的解决方案是首选

ondrop="return false;"添加到要禁用删除文本的元素中。

input {
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-user-drag: none;
}
<article>
  <input type="text" placeholder="Write text, select it, and drag" >
  <input type="text" placeholder="Then drop text here" ondrop="return false;">
</article>

最新更新