如何防止双击选择,但不能用css定期选择

时间:2017-02-13 07:59:10

标签: javascript html css mouse

我想要实现text button

所以用户应该点击它。但是当用户点击两次时,句子周围会有选择标记。所以我想要防止这种行为,但因为区域和按钮文本本身只是文本我想让用户能够像正常选择一样用鼠标手势选择文本。

所以,简而言之。 我如何防止双击选择但不是常规选择 并使解决方案具有挑战性如何使用CSS

2 个答案:

答案 0 :(得分:0)

尝试使用onselectstart =" return false" onmousedown =" return false"性的判定。像这样:

<input type="button" value="Button text" onselectstart="return false" onmousedown="return false" />

答案 1 :(得分:0)

来自其他问题https://stackoverflow.com/a/43321596/1919821

document.addEventListener('mousedown', function (event) {
  if (event.detail > 1) {
    event.preventDefault();
    // of course, you still do not know what you prevent here...
    // You could also check event.ctrlKey/event.shiftKey/event.altKey
    // to not prevent something useful.
  }
}, false);

//one line verstion
document.onmousedown = e => ((e.detail > 1)? (e.preventDefault():'')