从选择框中拖动所有选定元素的副本 - 可能吗?
我有一个选项列表 Web 界面:一对选择元素,它们之间有一对按钮(一个向左箭头和一个向右箭头)。用户可以通过例如选择左列中的选项之一并单击右向箭头来在两列之间移动项目。
现在我有一个增强请求:有人希望能够在两列之间拖放项目,而不是单击按钮。我最初的两个选择框设置的问题是,一旦我单击突出显示的选项之一来启动拖动,所有其他选定的选项都会被取消选择。使用 jQuery,我已将 mousedown 事件处理程序附加到选择框和每个仅在事件对象上调用 PreventDefault() 的选项,但这还不够。在 Firefox 3 上,单击的选项立即失去焦点,但所有其他选项仍然被取消删除,而在 IE6(遗憾的是我仍然必须支持)上,这没有任何区别。
所以我想我也许可以使用列表元素或 div 或其他东西创建一个合理的选择框传真。我可以创建一些在 Firefox 上运行的看起来合理的东西,但在 IE6 上,如果我按住 Shift 键并单击伪选择对象的一个元素(为了选择一系列选项),IE 将选择我所在位置之间的所有文本。单击和我最后单击的位置。同样,我已将 PreventDefault-ing mousedown、mouseup 和 click 处理程序附加到所有涉及的元素,但这没有帮助。
我什至尝试在原始选择框和伪选择对象上覆盖透明 div,想拦截鼠标点击并手动管理选择,但我无法使其在 IE 上工作。如果我使用选择框,我无法阻止单击更改选择,如果我使用看起来像选择元素的文本,我无法阻止它在按住 Shift 键的同时单击时选择一系列文本。
是否有一些通用的解决方案,或者我只是运气不好?
I have a picklist web interface: a pair of select elements with a pair of buttons (a left-pointing arrow and a right-pointing arrow) between them. Users can move items between the two columns by, eg, selecting one of options in the left column and clicking on the right-pointing arrow.
Now I have an enhancement request: someone wants to be able to drag-and-drop items between the two columns instead of clicking a button. The problem with my initial two-select-box setup is that as soon as I click one of the highlighted options to initiate a drag, all of the other selected options are deselected. Using jQuery, I've attached mousedown event handlers to both the select boxes and each individual option that just call preventDefault() on the event object, but this isn't sufficient. On Firefox 3 the clicked-on option loses focus immediately, but all other options are still deseleted, and on IE6 (which I regrettably still have to support) it makes no difference at all.
So I thought I could maybe create a reasonable facsimile of a select box using list elements or divs or something. I can create something reasonable-looking that works on Firefox, but on IE6, if I shift-click on an element of my pseudo-select object (in order to select a range of options), IE selects all of the text between where I click and the last place I clicked. Again, I've attached preventDefault-ing mousedown, mouseup, and click handlers to all of the elements involved, but it doesn't help.
I've even tried overlaying transparent divs over both my original select boxes and my pseudo-select objects, thinking to intercept mouse clicks and manage the selections manually, but I can't make it work on IE. If I use a select box, I can't prevent clicks from changing the selection, and if I use text that just looks like a select element, I can't prevent it from selecting a range of text on a shift-click.
Is there some general solution, or am I just out of luck?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看具有两个连接的可排序列表的 Jquery UI 可排序: http://jqueryui.com/demos /sortable/#connect-lists
只是:
Check out the Jquery UI Sortable with two connected sortable lists : http://jqueryui.com/demos/sortable/#connect-lists
It's just:
我最终选择了“不可选择”属性。
I ended up going with the "unselectable" attribute.