禁用 ctrl-click jquery ui 可选择
我想知道 jQuery UI Selectable 上是否有一个选项可以让我禁用 Ctrl+Click,但仍保留可拖动的多项选择。在我的项目中,我希望人们能够选择多个,但只能通过拖动,而不是通过 Ctrl + 单击。
如果没有,有人知道我可以实现这一目标的方法吗?
任何信息都会非常有帮助! :) 谢谢!!!
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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Selectable 使用 metaKey 标志来进行多选,因此您可以在调用 selectable 之前将 mousedown 上的 metaKey 绑定为 false。然后Ctrl+单击将始终处于关闭状态。确保在调用 selectable 之前进行绑定。
jsFiddle 此处
Selectable uses the metaKey flag to do multi-select, so you can bind metaKey to be false on the mousedown before calling selectable. Then Ctrl+click will always be off. Make sure to bind before calling selectable though.
jsFiddle here
上面这个好的解决方案还有另一种用途 - 如果您希望能够仅使用鼠标单击来完成所有选择/取消选择,而不需要按住 Ctrl 进行多选或取消选择 -只需始终将 EvilAmarant7x 示例中的 e.metaKey 设置为 true 即可。这正是我所需要的。
编辑:显然有人已经想到了这一点:使用 jQuery UI Selectable 实现多个选择:)
There is another usage of this good solution above - if you want to be able to just use your mouse click to do all the selecting/unselecting, without the need for holding the Ctrl for multiselects or for unselects - just always set the e.metaKey from EvilAmarant7x's example to true. It was exactly what I needed.
Edit: apparently someone already thought of that: Implement multiple selects with jQuery UI Selectable :)