2012-04-23 51 views
2

當使用idTabs jQuery插件時,如何添加在單擊選項卡時調用的函數?該文件說,這(但沒有給出例子):jQuery idTabs插件選項卡點擊功能

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 

我的代碼:當點擊選項卡時

<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); 

什麼也沒有發生 - 我會希望看到一個警告消息

回答

4

你是差不多了。你可以不喜歡它:

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

或者你可以使用匿名函數:

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