在 jquery-ui 对话框标题中显示下拉列表时出现问题
我正在使用 jQuery UI 库中的对话框组件。我想在其标题栏中显示一个简单的下拉菜单(
我尝试向尽可能多的事件添加事件处理程序,并取消它们的冒泡。更具体地说,我禁用了以下事件:onclick、onmousedown、onmouseup、onmouseover、onmouseout、onmouseenter、onmouseleave。这使得它在 Chrome/IE9 中变得更好,但 Opera 仍然闪烁很多,所以我认为仍然有问题。而且,这似乎有点……错误。
关于如何让下拉菜单正常工作有什么想法吗?
I'm using the Dialog component from the jQuery UI library. I'd like to show a simple dropdown (<select>
) inside its title bar. The component allows that (any HTML can be placed in the title bar), but it has issues: moving the mouse around in Opera flickers the dropdown a lot and in other browsers (Chrome, IE9) the dropdown cannot be opened.
I've tried adding event handlers to as many events as I could think and canceling bubbling on them. More specifically, I've disabled the following events: onclick, onmousedown, onmouseup, onmouseover, onmouseout, onmouseenter, onmouseleave. This makes it better in Chrome/IE9, but Opera still flickers a lot, so I suppose that something is still wrong. Also, this seems somehow... wrong.
Any ideas on how to get a dropdown working properly in there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几乎晚了两年才回答这个问题,但我遇到了同样的问题,最终得到了一个我想分享的更简单的解决方案。
默认情况下,jQuery UI 对话框在拖动时会忽略 .ui-dialog-content (对话框的内容)和 .ui-dialog-titlebar-close (标题元素中的右上角关闭按钮)。这是通过以下代码完成的:
这与添加到 title 元素的任何内容所需的行为相同。我可以使用以下代码将下拉列表添加到可拖动的“取消列表”中:
我在 open 方法中添加下拉列表,这就是我选择在那里修改取消的原因。另请注意,我的代码依赖于分配给对话框的自定义类名称,该名称是使用dialogClass选项设置的。
另请注意,如果对话框预定义的类名发生更改(.ui-dialog-content 和 .ui-dialog-titlebar-close),则取消将不再对这些元素起作用。
jQuery UI 对话框的 API:http://api.jqueryui.com/dialog/
Almost two years late to answer this, but I had the same problem and ended up with a simpler solution that I wanted to share.
The jQuery UI Dialog by default ignores .ui-dialog-content (the content of the dialog) and .ui-dialog-titlebar-close (top right close button in the title element) when dragging. This is done with the following code:
This is the same behavior needed for anything that is added to the title element. I was able to add my dropdown to the draggable "cancel list" by using the following code:
I'm adding my dropdown in the open method, which is why I chose to modify cancel there. Also note that my code relies on a custom class name assigned to the dialog, which is set with dialogClass option.
One more note, if the class names pre-defined by the dialog ever change (.ui-dialog-content and .ui-dialog-titlebar-close), the cancel will no longer work on those elements.
API for jQuery UI Dialog: http://api.jqueryui.com/dialog/
http://jsfiddle.net/a9ntp/13/
我已经弄乱了它几分钟现在,我想我可能会给你一个解决方案。这是我第一次使用小提琴,所以如果它不起作用请告诉我。据我所知,出现这个问题是因为 dialgo 弹出窗口上的标题栏是可拖动的。
当鼠标悬停在下拉列表上时,它将禁用拖动来选择对象。当它离开下拉列表时,它应该重新初始化拖动功能。希望对您有帮助或至少给您一些想法!
http://jsfiddle.net/a9ntp/13/
I have been messing with it for a few minutes now, and I think I might have a solution for you. This is the first time I've used fiddle, so if it doesn't work let me know. As far as I can tell, the issue comes up because the title bar on the dialgo popup is draggable.
When the mouse hovers on the drop down list, it will disable the drag letting you select the object. When it leaves the drop down list, it should reinitialize the dragging functionality. Hope that helps or at leasts gives you some ideas to work on!!!