gpt4 book ai didi

jquery - 当用户使用 jQuery 双击任意位置时取消选择

转载 作者:行者123 更新时间:2023-12-01 01:04:16 24 4
gpt4 key购买 nike

如您所知,当用户双击某处时,资源管理器会尝试选择最近的对象(例如文本、表格行等),如下图所示: enter image description here

用户可以:

  • 一键选择任何文本

用户不能

  • 通过双击选择任何对象(换句话说,当用户双击列表时,jquery 应该取消选择所选区域)

那么我该怎么做呢?希望它是清楚的。

注意:我使用的是双击操作来进入该项目。

最佳答案

我忘了,这是无法在事件中取消默认操作的边缘情况之一。在这种情况下,您可能需要对 Firefox 和 Chrome 使用 CSS 方法:

-moz-user-select: none;
-webkit-user-select: none;

对于 Opera/IE:

$("#mytable td").prop("unselectable", "on");  // jQuery 1.6+
$("#mytable td").attr("unselectable", "on"); // jQuery 1.5-
<小时/>

如果您希望用户仍然能够拖动选择,您可能需要使用如下解决方案:

$("#mytable td").bind("dblclick", function () {
var $this = $(this);
$this.prop("unselectable", "on").css({
"moz-user-select" : "none",
"-webkit-user-select" : "none"
});

window.setTimeout(function () {
var $this = $(this);
$this.prop("unselectable", "").css({
"moz-user-select" : "",
"-webkit-user-select" : ""
});
}, 0);
});

关于jquery - 当用户使用 jQuery 双击任意位置时取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6087249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com