我要实现text button
.
所以用户应该点击它。 但是当用户单击两次时,句子周围都有选择标记。 所以我想防止这种行为,但由于区域和按钮文本本身只是文本,我希望用户能够像正常选择一样使用鼠标手势选择文本。
所以,简而言之。我如何防止双击选择而不是常规选择并使解决方案具有挑战性如何使用CSS完成
尝试使用 onselectstart="return false" onmousedown="return false" properies.像这样:
<input type="button" value="Button text" onselectstart="return false" onmousedown="return false" />
来自其他问题 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():'')