9

I was wondering if there is an option on the jQuery UI Selectable that will let me disable the Ctrl+Click, but still keep the draggable for the multiple selection. On my project I want to be able for people to select multiples, but only by dragging, not by Ctrl+clicking.

If there isn't, does anyone know a way I can achieve this?

Any information would be really helpful! :) Thanks!!!

4

3 回答 3

12

Selectable 使用 metaKey 标志进行多选,因此您可以在调用 selectable 之前在 mousedown 上将 metaKey 绑定为 false。然后Ctrl+click 将始终关闭。确保在调用 selectable 之前绑定。

$('#selectable').bind("mousedown", function (e) {
            e.metaKey = false;
 }).selectable()

jsFiddle在这里

于 2011-04-01T19:28:33.610 回答
3

上面这个好的解决方案还有另一种用法 - 如果您希望能够只使用鼠标单击来完成所有选择/取消选择,而无需按住Ctrl多选或取消选择 - 只需始终设置 e.metaKey from EvilAmarant7x 的例子是真实的。这正是我所需要的。

编辑:显然有人已经想到了:使用 jQuery UI Selectable 实现多项选择:)

于 2011-04-11T19:44:58.310 回答
2
$("#selectable").on("selectablestart", function (event, ui) {
event.originalEvent.ctrlKey = false;
});
于 2014-04-18T07:22:31.180 回答