如您所知,当用户双击某处时,资源管理器会尝试选择最近的对象(例如文本,表格行等),如下图所示:
那我该怎么做呢?希望很清楚。
注意:我使用双击操作输入项目。
答案 0 :(得分:5)
我忘记了,这是在事件中无法取消默认操作的边缘情况之一。在这种情况下,您可能希望对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);
});
答案 1 :(得分:0)
选择一些随机元素和
$("#randsmallelement").focus();
如果不起作用,请尝试添加
$("#randsmallelement).select();