jquery ui 手风琴禁用点击

发布于 2024-11-26 01:30:17 字数 426 浏览 1 评论 0原文

我有一个像这样的手风琴集

$(".accordion-form").accordion({
    collapsible:false,
    autoHeight: false,
    changestart: checkChanged,
    change: function(e, ui) {active = $( ".accordion-form" ).accordion( "option", "active");},
    active: 0
});

active 是一个静态变量,它始终具有活动内容。

我想做的是在活动标题之前启用标题以供单击,并在活动标题之后禁用标题以供单击。

这样我就可以让手风琴表现得像一种形式,“你可以后退,但在完成这部分之前不能前进”。

任何帮助将不胜感激

I have an accordion set like this

$(".accordion-form").accordion({
    collapsible:false,
    autoHeight: false,
    changestart: checkChanged,
    change: function(e, ui) {active = $( ".accordion-form" ).accordion( "option", "active");},
    active: 0
});

active is a static variable which always have the active content.

What I would like to do is enable headers before the one actived for clicking, and the headers after the active one been disabled for clicking.

This way I can make the accordion act like a form in the way of "you can go back but no forward til your finish this part".

Any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终 2024-12-03 01:30:17

虽然我同意 Frédéric 的观点,即手风琴对于这种行为来说并不是一个很好的小部件,但您应该能够使用一些简单的 JS 来做到这一点。将另一个“onclick”处理程序附加到手风琴标头,并在标头距离太远时终止该事件:

$('.accordion-form .ui-accordion-header').click(function(e) {
    if($(this).index() > current_section.index())
    {
        e.stopImmediatePropagation();
    }
});

这需要您有一个 current_section 变量来保存最后一个已完成的部分(我假设您已经有类似的东西),并确保该处理程序在 JqueryUI 手风琴设置之后(或之前)附加,以便您的处理程序首先被调用。

希望这有帮助!

While I agree with Frédéric that an accordion isn't a great widget for this sort of behaviour, you should be able to do it with some simple JS. Attach another 'onclick' handler to the accordion headers, and have it kill the event if the header was too far along:

$('.accordion-form .ui-accordion-header').click(function(e) {
    if($(this).index() > current_section.index())
    {
        e.stopImmediatePropagation();
    }
});

That'll need you to have a current_section variable that holds the last section completed (I assume you already have something like this), and make sure this handler gets attached after (or before) the JqueryUI accordion setup, so your handler gets called first.

Hope this helps!

疑心病 2024-12-03 01:30:17

我在其他地方找到了这个问题的解决方案:

// Add the class ui-state-disabled to the headers that you want disabled
$( ".whatyouwantdisabled" ).addClass("ui-state-disabled");

现在实现禁用功能的技巧:

// replace the old eventhandler
var accordion = $( "#accordion" ).data("accordion");
accordion._std_clickHandler = accordion._clickHandler;
accordion._clickHandler = function( event, target ) {
 var clicked = $( event.currentTarget || target );
 if (! clicked.hasClass("ui-state-disabled")) this._std_clickHandler(event, target);

每当您想重新激活选项卡时,请执行以下操作:

// Remove the class ui-state-disabled to the headers that you want to enable
$( ".whatyouwantenabled" ).removeClass("ui-state-disabled");

来源:https://forum.jquery.com/topic/disable-enable-sections-of-accordion

I found the solution to this problem elsewhere:

// Add the class ui-state-disabled to the headers that you want disabled
$( ".whatyouwantdisabled" ).addClass("ui-state-disabled");

Now the hack to implement the disabling functionality:

// replace the old eventhandler
var accordion = $( "#accordion" ).data("accordion");
accordion._std_clickHandler = accordion._clickHandler;
accordion._clickHandler = function( event, target ) {
 var clicked = $( event.currentTarget || target );
 if (! clicked.hasClass("ui-state-disabled")) this._std_clickHandler(event, target);

Whenever you want to re-activate a tab, do:

// Remove the class ui-state-disabled to the headers that you want to enable
$( ".whatyouwantenabled" ).removeClass("ui-state-disabled");

Source: https://forum.jquery.com/topic/disable-enable-sections-of-accordion

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文