jQuery idTabs plugin tab click function

混江龙づ霸主 提交于 2019-12-24 05:03:07

问题


When using the idTabs jQuery plugin how do you add function that is called when a tab is clicked? The documentation says this (but gives no example):

click (function) 
Function will be called when a tab is clicked. ex: $(...).idTabs(foo) 
If the function returns true, idTabs will show/hide content (as usual). 
If the function returns false, idTabs will not take any action. 
The function is passed four variables: 
  The id of the element to be shown 
  an array of all id's that can be shown 
  the element containing the tabs 
  and the current settings 

My code:

<ul class="idTabs"> 
  <li><a href="#jquery">jQuery</a></li> 
  <li><a href="#official">Tabs 3</a></li> 
</ul> 
<div id="jquery">If you haven't checked out ...</div> 
<div id="official">idTabs is only a simple ...</div>

function tabChanged(id, tabs, parent, settings) {
    alert('tabChanged');
    return true;
}

$(".idTabs").idTabs(tabChanged);

Nothing happens when the tab is clicked - I would expect to seen an alert message


回答1:


You are almost there. You can do it like:

$(".idTabs").idTabs({click: tabChanged});

Or you can use an anonymous function:

$('.idTabs').idTabs({
    click: function(id, all, container, settings){
        alert('tabChanged');
        return true;
    }
});


来源:https://stackoverflow.com/questions/10274144/jquery-idtabs-plugin-tab-click-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!