Jquery UI SELECTABLE,如何仅选择一项?
有没有什么方法可以定义,使用 jquery.selectable 小部件只能选择一个项目?
或者我必须实现一个捕获事件并由我自己操纵会发生什么的解决方法?
is there any way to define that, only one item can be selected with jquery.selectable widget?
Or i've to inmplement a workarround capturing events and manipulating by my self what happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我扩展了 Nirmal 的答案以限制鼠标选择情况。另外,我觉得使用
selected
选项比使用完全独立的事件处理程序更干净。还剩下一个小问题。使用鼠标选择多个项目时,将始终选择最后一个项目。这是因为传递到
selected
选项的函数是为每个选定的项目运行的,我假设它是按项目顺序排列的。理想情况下,将选择鼠标光标所在的项目。我没有修复这个问题,因为我主要只是想在使用鼠标时有一个多重选择约束。I expanded on Nirmal's answer to limit the mouse select case. Also, I feel that it is cleaner to use the
selected
option rather than a completely separate event handler.There is one minor problem remaining. When selecting multiple items with the mouse the last item will always be selected. This is because the function passed into the
selected
option is run for each selected item, which I assume goes in item order. Ideally the item that your mouse cursor lands at would be selected. I didn't fix this because I mainly just wanted a multiple selection constraint when using the mouse.我稍微改进了 mattblang 的答案。兄弟姐妹也可以有后代,所以更普遍的答案是:
I improve mattblang's answer a little. Siblings can have also descendants, so more general answer is: