0

我有一个非常适合加载远程内容的 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>
4

1 回答 1

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
                }
            }
        });
});
于 2011-03-25T14:23:22.783 回答