简体   繁体   English

jQuery UI Tabs选择功能不起作用

[英]jQuery UI Tabs select function not working

I have the following jquery which is used to create tabs on my website (wrapped in document ready function): 我有以下jquery用于在我的网站上创建标签(包装在文档就绪功能中):

$('#understanding-water-management').tabs({
    select: function(event, ui) {
        alert('hi');
    }
});

However, on my site the select function isn't been fired on tab change. 但是,在我的网站上,选项卡更改未启用选择功能。 I have created a fiddle but this works as I would expect it to (it alerts hi on tab change). 我创建了一个小提琴,但是它能按我期望的那样工作(它在标签更改时发出警报)。

The only difference between the two sites is that on my own website I have used a lighter version of jQuery UI where I have only downloaded the Core, Widget (from UI Core) and Tabs (from Widgets) options. 这两个站点之间的唯一区别是,在我自己的网站上,我使用的是jQuery UI的较轻版本,其中我仅下载了Core,Widget(来自UI Core)和Tabs(来自Widget)选项。 Is there any other option I need to download to get the select function above to work - I don't want to use the full jQuery UI as all I need is the tabs so want to make my js files as minimal as possible 我还需要下载其他选项才能使上面的select功能正常工作-我不想使用完整的jQuery UI,因为我只需要使用选项卡即可,因此希望使我的js文件尽可能少

Try to wrap your code inside DOM ready handler $(function() {...}); 尝试将代码包装在DOM ready处理程序$(function() {...}); to make sure all your DOM elements are loaded properly before executing your jQuery code: 确保在执行jQuery代码之前正确加载所有DOM元素:

$(function() {
    $('#understanding-water-management').tabs({
        select: function(event, ui) {
            alert('hi');
        }
    });
});

Your jsFiddle works because they've done above part for you by default when you include jQuery. 您的jsFiddle有效,是因为当您包含jQuery时,默认情况下它们已经为您完成了上述工作。

jQuery UI 1.10 change the select to beforeActivate (if you want the function to fire before the tab is selected) or activate (if you want it to fire after the tab has been selected) jQuery UI 1.10将select更改为beforeActivate (如果您希望在选择选项卡之前触发该功能)或activate (如果您希望在选择选项卡之后触发该功能)

try 尝试

$('#understanding-water-management').tabs({
    beforeActivate: function(event, ui) {
        alert('hi');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM