制作“添加选项卡” jQuery UI 选项卡上的按钮
我的网页中有一个 jQuery UI 选项卡控件,我想制作一个与选项卡标题具有相同外观的“添加选项卡”按钮(位于“选项卡栏”中,与其他选项卡标题一起)。我在列表中添加了一个项目,具有特定的类,允许我使其浮动在右侧。但我无法删除 jQuery 添加的默认操作(单击时打开相关选项卡),这会导致错误,因为该选项卡不存在。
我尝试了几种方法:
- 禁用选项卡使其在屏幕上淡出(删除我想要的 css)
- 使用
unbind
不会删除 onClick 侦听器。 - 设置另一个 onClick 监听器也不起作用,因为它被简单地忽略了......
我对此失去了理智。任何人都可以帮助我保持理智吗?
I have a jQuery UI tab control in my web page, and i want to make an "Add Tab" button having the same look than the tab titles (and located in the "tab bar", with other tab titles). I added an item in the list, with a specific class allowing me to make it float on the right. But I cannot remove the default action added by jQuery (on click, open related tab), which leads to an error, because the tab doesn't exist.
I tried several methods :
- Disabling the tab makes it fade on the screen (removing the css I want)
- Using
unbind
does not remove the onClick listener. - Setting another onClick listener does not work either, as it is simply ignored...
I'm losing my mind on this. Anyone can help me stay sane ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
select
事件并在以下情况下捕获该事件:单击您的选项卡。您可以在其中创建一个新选项卡并给予该焦点。You could use the
select
event and catch the event when clicked on your tab. In there you could make a new tab and give that focus.正如 Jerone 指出的,
select
事件是您的朋友。将“添加”选项卡的 url 设置为“#Add”(或可用于唯一标识该选项卡的其他值)
在事件处理程序内,检查 ui.tab.hash 的值,以检查此哈希值是否存在,如果存在,则创建新选项卡,选择它,然后返回“false”。如果哈希值与您的魔法值不匹配,则返回“true”,以使选项卡选择过程正常继续。
As Jerone pointed out, the
select
event is your friend.Set the url of your 'Add' tab to "#Add" (Or some other value that can be used to uniquely identify that tab)
Inside the event handler, check the value of ui.tab.hash, to check if this hash value is present and , if so, create the new tab, select it, and return 'false'. If the hash value doesn't match you magic value, then return 'true', to let the tab selection process continue as normal.