如何禁用 jquery 手风琴的某些链接
我目前在导航部分实现了基于 jquery 的手风琴,但导航的某些部分不需要成为手风琴的一部分(如果没有类别等)我只是想知道是否可以禁用部分导航手风琴与否?
我感觉这可能是不可能的,但这个网站之前曾让我感到惊讶:)
非常感谢。
I am currently implemented a jquery based accordion on a navigation section, but some parts of the navigation don't need to be part of the accordion (if there are no categories etc) i am just wondering if it is possible to disable parts of the accordion or not ?
i get the feeling this could be impossible but this site has surprised me before :)
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
由于事件的绑定顺序,上一个技巧不起作用,但以下技巧有效:
每当您想要激活选项卡时,请执行以下操作:
就是这样
Previous trick does not work because of the binding order of events, but the following works:
Whenever you want to activate a tab, do:
That's it
一种简单的方法可能是使用 unbind 方法:
在要禁用的元素中添加 ui-state-disabled。
A simplistic way maybe using the unbind method:
Adding the ui-state-disabled in the elements you want disable.
您可以对要禁用的事物进行分类。
然后做:
或类似的事情
You can put classes on the things you want to disable.
Then do :
or something similar
喜欢主页链接吗?我想要一个在我的手风琴顶部“常规”样式的主页链接。我正在使用 Google 的 1.8 UI 版本:
未缩小:
我在手风琴的 _clickHandler 方法(第 5834 行左右)中对手风琴进行了一些修改。我在“var clicked =”之后添加了以下代码:
Like for a home link? I wanted a home link styled "regularly" at the top of my accordion. I'm using Google's 1.8 UI version:
Un-minified:
I hacked the accordion a bit in its _clickHandler method (line 5834-ish). I added the following code just after the "var clicked = ":
我将选项 linkDisabled 添加到插件中。通过这种方式,您可以为手风琴对象内的链接定义一个类,这些链接被禁用。例如:
这是重写的插件:
i added the option linkDisabled to the plugin. this way you can define a class for the links inside the accordion object, which are disabled. e.g.:
and here's the rewritten plugin:
我有类似的问题。我需要一个 5 部分的手风琴,但在前三部分(提示不同的操作)完成之前,后两部分无法访问。以下是我处理它的方法(使用 2 个单独的手风琴):
HTML:
Javascript:
这样,我们设置了第二个手风琴,以便它开始时处于禁用状态。此外,它还被赋予了 CSS 类“faded_out”,它提供了一些不透明度并将鼠标光标设置为默认的锚点。最后,当单击任一手风琴时,它会将另一个手风琴的“激活”设置为 false,以便关闭另一个手风琴并使其看起来像是同一个手风琴的一部分。这对我来说非常有效。
PS 我的应用程序位于轨道上,为了检测是否应启用第二个手风琴(通过 ReleaseAccordion2 函数),我查找传递给第一个手风琴中的 h3 的类(“完整”)(通过嵌入式 ruby )。
I had a similar problem. I needed a 5 part accordion, but the last two parts were not to be accessible until the first three (which prompted for different actions) were completed. Here's how I handled it (using 2 separate accordions):
HTML:
Javascript:
This way, we set up the second accordion so that it starts out disabled. Moreover, it is given CSS class 'faded_out' which gives some opacity and sets the mouse cursor to default for anchors. Finally, when either accordion is clicked, it sets 'activate' to false on the other so as to close the other accordion and make it seem like they are part of the same one. This works very well for me as is.
P.S. My app is on rails, and in order to detect whether or not the second accordion should be enabled (via the ReleaseAccordion2 function), I look for a class ('complete') passed to the h3's in the first accordion (via embedded ruby).
您可以为此使用“beforeActivate”事件。
向 h3 元素添加禁用类
将以下函数设置为“beforeActivate”事件。可以通过“ui.newHeader”对象访问标头对象。测试标头是否具有“accordionDisable”类,如果为 true,则返回 false,它将阻止手风琴部分激活。
要激活手风琴部分,请删除 'accordionDisable' 类
You can use the 'beforeActivate' event for this.
Add a disable class to your h3 element
Set the below function to the 'beforeActivate' event. The header object can be accessed via the 'ui.newHeader' object. Test if the header has 'accordionDisable' class, if true then return false and it will stop the accordion section from activating.
To activate the accordian section remove the 'accordionDisable' class
对要包含的部分使用类,并在初始化手风琴时创建更具体的 CSS 选择器。
Use classes for the section you want to include, and make a more specific CSS selector when initializing the accordion.
Marcgg 的答案似乎是正确的。您可以做的是将类添加到您想要在手风琴中启用的链接,从中获取 href,然后通过设置 window.location 来导航 url。
Marcgg's answer seems to be on the right track. What you could do is add class to the links you want enabled in the accordion, get the href from them and then navigate url by setting the window.location.
我有同样的问题。我想加入一个不属于手风琴一部分的 div。它是一个 div,而手风琴中的其他元素是 。我添加了 header: '' 选项,这阻止了类被添加到我拥有的 div 中。
I had the same issue. I wanted to stick in a div that wasn't a part of the accordion. It was a div whereas the other elements in the accordion were . I added the header: '' option and this prevented the classes from being added to the div that I had.
我似乎无法获得与我正在使用 ATM(版本 1.8)的 jQuery UI 版本一起使用的解决方案,
我确实找到了另一个解决方案;
I can't seem to get the solutions given to work with the version of jQuery UI I'm using ATM (Version 1.8)
I did find another solution;