打开手风琴时如何在锚标签内触发网址?

时间:2015-05-28 12:57:38

标签: javascript jquery jquery-ui-accordion

假设我有以下代码:

<div id="accordionLeftNav">
    <div class="accordionBox" id="accordionStyle">
        <h3><a href="url">Here</a></h3>
    </div>
</div>

现在我有以下js

if ($("#accordionLeftNav").length > 0) {
    $("#accordionLeftNav").accordion({
        header: "h3",
        heightStyle: "content",
        collapsible: true,
        navigation: true,
        active: false,
        icons: {
            "header": "open",
            "activeHeader": "close"
        }
    });
}

现在我想在打开手风琴时触发锚标签内的url。 请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我已经修好了。这是代码:

if ($("#accordionLeftNav").length > 0) {
            $("#accordionLeftNav").accordion({
                header: "h3",
                heightStyle: "content",
                collapsible: true,
                navigation: true,
                active: false,
                icons: { "header": "open", "activeHeader": "close" },
                activate: function( event, ui ) {
                var headerUrl = ui.newHeader.find('a').attr("href");
                window.location = headerUrl;
            }
            });

        }