2011-03-25 81 views
0

我有一个jQuery tabs元素,在加载远程内容方面非常出色。jQuery制表符自定义动作!

但是我想添加一个按钮叫说“复位”来调用自定义的JavaScript。对于jQuery来说,这是相当新颖的东西,但是喜欢它,并且无法解决如何完成这个任务。

这里是让此刻的选项卡中的.js文件,这是从jQuery网站的默认!

$(document).ready(function() { 
$("#tabs").tabs({ 
     ajaxOptions: { 
      error: function(xhr, status, index, anchor) { 
       $(anchor.hash).html(
        "Couldn't load this tab. We'll try to fix this as soon as possible."); 
      } 
     } 
    }); 
}); 

然后在我的PHP中,我有以下几点。我想将自定义操作附加到新的“重置”选项卡上。

<div id="tabs"> 
<ul> 
    <li><a href="#map_canvas" title="content">Home</a></li> 
    <li><a href="test.php" title="content">How this works?</a></li> 
    <li><a href="test.php" title="content">View this at home</a></li> 
    <li><a href="#reset" title="content">Reset</a></li> 
</ul> 

<div id="map_canvas"> 
</div> 

</div> 

回答

2

这些选项卡有一个select事件,您可以将其放入构造器选项对象中。

$(document).ready(function() { 
    $("#tabs").tabs({ 
      ajaxOptions: { 
       error: function(xhr, status, index, anchor) { 
        $(anchor.hash).html(
         "Couldn't load this tab. We'll try to fix this as soon as possible."); 
       } 
      }, 
      select: function (event, ui) { // run this when a new tab is clicked 
       if ($(ui.tab).attr('href') == "#reset") { 
        // Do stuff here 
       } 
      } 
     }); 
}); 
+0

大,似乎是最好的解决方案! – 2011-03-25 14:54:12