如何在 JQuery UI Selectable 上实现切换功能?
我正在使用 JQuery UI - 可选择。如果该元素已被按下并且已被选择(切换),我想取消选择该元素,
您能帮我添加此功能吗!
I'm using JQuery UI - Selectable. I want to deselect the element if it has been pressed and it has already been selected (toggle)
Could you help me to add this functionality please !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于所有的类回调,你不会做得比这更好:
Because of all the class callbacks, you're not going to do much better than this:
如果您在单击时按住 Ctrl 键,则您已经可以通过 jQuery UI 选择该功能。
如果您确实需要将其作为默认功能,则不需要使用 selectable,您可以将其作为简单的 onclick 处理程序来完成,就像 nolabel 建议的那样。
或者...您也可以编辑jquery.ui.selectable.js并添加一个选项来满足您的需要。不应该太难,有 4 个地方检查 event.metaKey ,确保您的选项已设置,只需运行代码路径,就好像 event.metaKey 始终为 true 一样。
由于可选内容可以使用更多自定义功能,您还可以向 jQuery UI 开发人员提出功能请求,将其包含在下一个正式版本中。
You already have that functionality with jQuery UI selectable if you're holding down the Ctrl key while clicking.
If you really need that as the default functionality, you don't need to use selectable, you can do it just as a simple onclick handler, like what nolabel suggested.
Or... you might as well edit jquery.ui.selectable.js and add an option which does just what you need. Shouldn't be too hard, there are 4 places where event.metaKey is checked, make sure if your option is set, just run the codepaths as if event.metaKey was always true.
As the selectables could use some more customisation, you could also make a feature request for jQuery UI developers to include it in the next official version.
您必须在代码中注入两个简单的元素才能实现您想要的效果。每当您需要反转/切换功能时,这只会反转元密钥布尔值。
You have to inject two simple elements in the code to achieve what you want. This just inverts the metaKey boolean, whenever you need inverted/toggle functionality.