【问题标题】:Toggle container when external link is clicked单击外部链接时切换容器
【发布时间】:2011-08-24 18:47:28
【问题描述】:

我使用这里的切换教程http://www.sohtanaka.com/web-design/easy-toggle-jquery-tutorial 并想出了这个网站。

网站上只有 1 个切换链接。

我的问题是,我有一个 html 时事通讯,其中需要放置一个链接,当它被点击时,它会转到网站并自动关注切换链接。切换链接也应该会自动打开,而无需单击它。

我怎样才能做到这一点?

【问题讨论】:

    标签: jquery toggle


    【解决方案1】:

    您的 HTML 简报中的链接应包含查询字符串或链接上的哈希,如下所示:

    http://publicis-malaysia.com/ipad2/index.html?autofocus
    

    http://publicis-malaysia.com/ipad2/index.html#autofocus
    

    然后你可以在 jQuery 代码中检测到这一点:

        if (location.hash.indexOf('autofocus') > -1) {
            $('.trigger').click();
        }
    

    这将在页面打开时检查文档哈希中的“自动对焦”,然后单击该元素。如果你想使用查询字符串(“?autofocus”),你应该在示例代码的第一行使用'search'而不是'hash'。

    您可以将代码放在您从教程中获取的代码之后,放在头部的脚本块中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    相关资源
    最近更新 更多