我看到很多例子,但我仍然没有得到它! 我尝试在另一页上打开手风琴小组。
我的目标:
当我们点击A页上的特定链接时,我们会被重定向到手风琴data-id =' 32'在第B页上。
我的工作网址:www.mysite.ccc / page /?sub = 32 #milmedia
网址重定向到ID 32,但未打开ID 32。
<ul class="accordion">
<li class="accordion__item"><div class="underline-list__item js-accordion-open" data-id="30"><div class="underline-list__link">
<div class="underline-list__text"><h3>Title</h3><span class="accordion_button"><span class="accordion_button_icon"></span></span></div></div></div>
<div class="accordion__content js-accordion-content"><div class="wysiwyg">
my content
</div></div></li>
<li class="accordion__item"><div class="underline-list__item js-accordion-open" data-id="32"><div class="underline-list__link">
<div class="underline-list__text"><h3 id="milmedia">Title</h3><span class="accordion_button"><span class="accordion_button_icon"></span></span> </div></div></div>
<div class="accordion__content js-accordion-content"><div class="wysiwyg">
my content
</div></div></li>
<li class="accordion__item"><div class="underline-list__item js-accordion-open" data-id="42"><div class="underline-list__link">
<div class="underline-list__text"><h3>Title</h3><span class="accordion_button"><span class="accordion_button_icon"></span></span></div></div></div>
<div class="accordion__content js-accordion-content"><div class="wysiwyg">
my content
</div></div></li>
</ul>
我的jQuery尝试:
jQuery(document).ready(function($) {
var check = location.hash;
if (check == "milmedia") {
$(window).load(function()
{
$('.js-accordion-open[data-id=32]').trigger('click');
});
}
});
Using this version: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
** If I do that, it's working perfectly, but the "if" is missing
$(window).load(function()
{
$('.js-accordion-open[data-id=32]').trigger('click');
});
抱歉我的英语不好,我是法国人! 提前谢谢!
答案 0 :(得分:0)
好的,我发现了!
$(function(){
if (window.location.hash == "#dfse") {$('.js-accordion-open[data-id=33]').trigger('click');}
else if (window.location.hash == "#tyjh") {$('.js-accordion-open[data-id=32]').trigger('click');}
else if (window.location.hash == "#ngfc") {$('.js-accordion-open[data-id=31]').trigger('click');}
else {return false;}
});