Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从外部链接打开手风琴_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 从外部链接打开手风琴

Javascript 从外部链接打开手风琴,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我找到了一些可能有用的代码,但我无法解释如何更改它,使其与我当前的手风琴结构兼容 以下是我找到的修复方法: $(function () { $(".tab-content").hide().first().show(); $(".inner-nav li:first").addClass("active"); $(".inner-nav a").on('click', function (e) { e.preventDefault(); $(this).closest('li'

我找到了一些可能有用的代码,但我无法解释如何更改它,使其与我当前的手风琴结构兼容

以下是我找到的修复方法:

$(function () {
$(".tab-content").hide().first().show();
$(".inner-nav li:first").addClass("active");

$(".inner-nav a").on('click', function (e) {
    e.preventDefault();
    $(this).closest('li').addClass("active").siblings().removeClass("active");
    $($(this).attr('href')).show().siblings('.tab-content').hide();
});

var hash = $.trim( window.location.hash );

if (hash) $('.inner-nav a[href$="'+hash+'"]').trigger('click');

});
这是我页面上手风琴的一部分:

<div class="container">
<div class="accordion-trigger">
<h3>Wedding</h3>
</div>
<div class="accordion-container">
<p>
<tab>
<bgcolor class="shadow">
<a href="pdf/MyLifestyle_WeddingPackages_020616_01.pdf"><font color="black" size="+1"><strong>Wedding Packages PDF</strong></font></a>
</bgcolor>
</tab>
</p>
<hr class="separator1"> 
</div>

婚礼


在div容器中还有其他几个div class=“accordion trigger”,当您单击时会被激活。当然,只有第一个手风琴在加载页面上处于活动状态


上面的修复程序应该检查哈希ID,并对哈希ID执行单击事件。

由于您使用的是未提供的CSS,因此要打开导航:

$(function () {
    var hash = parseInt($.trim(window.location.hash)), // hash as number
        $triggers = $('.accordion-trigger'); // list of triggers
    if (hash) { // if hash exists
        if($triggers.length >= hash) { // if not greater than number of triggers
            $triggers.eq(hash+1).trigger('click'); // open n-th item
        }
    }
});
example.com/site/#4
应打开第四项(如果存在)。
顺便说一下,这是一个糟糕的代码。

如何识别活动选项卡?凭订单?正确的散列应该是什么?当点击它时,它会通过CSS(我相信)按照DW的指示变为活动的。在活动的“手风琴触发器”上变为活动的。我不确定是否可以给每个手风琴触发器它自己的ID谢谢你的建议,我一定会尝试的。会让你知道结果的。顺便问一下,哪种代码很糟糕?询问学习目的。如果页面上有此模块的多个实体,则此模块将不起作用。它无法缩放。如果您正在使用CSS,请考虑使用它来在加载时打开适当的选项卡,通过将哈希作为JavaScript添加到Shar元素来打开。混合是不好的做法。