页面加载后重新打开上一节中的 jQuery 手风琴
我编写了自己的 Jquery 手风琴代码,但遇到了问题。
我需要在点击链接后再次打开当前部分。
当我单击链接时,某些数据库代码会获取正确的数据并显示它,但是由于页面已重新加载,先前打开的手风琴部分现已关闭。
有人对使用 '$accordionPrev' 值有任何建议吗?我尝试访问此变量,但任何使其可见的请求都不起作用。
我将非常感谢任何帮助,我一整天都在为此奋斗:)
非常感谢
Robert
Jquery:
var $runAccordionOnce = 0; var $accordionPrev;
$(".sidebar_game_header").click(function(){
if($runAccordionOnce > 0) {
$accordionPrev.slideUp('normal');
$accordionPrev.prev().css({'background-position' : 'top left'});
}
if($(this).next().is(":hidden")){
$accordionPrev = $(this).next();
$(this).next().slideDown('normal');
$(this).css({'background-position' : 'bottom left'});
$runAccordionOnce++;
}
HTML 示例:
<div class="sidebar_game_content_wrapper"><div class="sidebar_game_onepix"></div>
<div class="sidebar_game_header"><img src="<?php bloginfo('template_directory'); ?>/images/icn_game1.png" alt="Game 1 Icon"/><div class="sidebar_game_header_text">Game 1</div></div>
<div class="sidebar_game_content">
<ul>
<li><a href="<?php {echo $url . "&game_id=10&platform_id=3";} ?>">iPhone</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=4";} ?>">iPad</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=2";} ?>">Mac</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=1";} ?>">PC</a></li>
</ul>
</div>
</div>
<div class="sidebar_game_content_wrapper"><div class="sidebar_game_onepix"></div>
<div class="sidebar_game_header"><img src="<?php bloginfo('template_directory'); ?>/images/icn_game2.png" alt="Game 2 Icon"/><div class="sidebar_game_header_text">Game 2</div></div>
<div class="sidebar_game_content">
<ul>
<li><a href="<?php {echo $url . "&game_id=9&platform_id=3";} ?>">iOS</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=2";} ?>">Mac</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=1";} ?>">PC</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=6";} ?>">Nintendo DS</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=5";} ?>">Nintendo Wii</a></li>
<hr />
</ul>
</div>
I coded my own Jquery accordion and I have a problem.
I need to open the current section again after following the link.
When I click a link some database code fetches the correct data and displays it however since the page has re-loaded the previously open accordion section is now closed.
Does anybody have any recommendations for making use of the '$accordionPrev' value? I tried accessing this var but any requests to make it visible were not working.
I would be very grateful for any help, I have been fighting this all day :)
Many thanks
Robert
Jquery:
var $runAccordionOnce = 0; var $accordionPrev;
$(".sidebar_game_header").click(function(){
if($runAccordionOnce > 0) {
$accordionPrev.slideUp('normal');
$accordionPrev.prev().css({'background-position' : 'top left'});
}
if($(this).next().is(":hidden")){
$accordionPrev = $(this).next();
$(this).next().slideDown('normal');
$(this).css({'background-position' : 'bottom left'});
$runAccordionOnce++;
}
HTML Sample:
<div class="sidebar_game_content_wrapper"><div class="sidebar_game_onepix"></div>
<div class="sidebar_game_header"><img src="<?php bloginfo('template_directory'); ?>/images/icn_game1.png" alt="Game 1 Icon"/><div class="sidebar_game_header_text">Game 1</div></div>
<div class="sidebar_game_content">
<ul>
<li><a href="<?php {echo $url . "&game_id=10&platform_id=3";} ?>">iPhone</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=4";} ?>">iPad</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=2";} ?>">Mac</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=10&platform_id=1";} ?>">PC</a></li>
</ul>
</div>
</div>
<div class="sidebar_game_content_wrapper"><div class="sidebar_game_onepix"></div>
<div class="sidebar_game_header"><img src="<?php bloginfo('template_directory'); ?>/images/icn_game2.png" alt="Game 2 Icon"/><div class="sidebar_game_header_text">Game 2</div></div>
<div class="sidebar_game_content">
<ul>
<li><a href="<?php {echo $url . "&game_id=9&platform_id=3";} ?>">iOS</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=2";} ?>">Mac</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=1";} ?>">PC</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=6";} ?>">Nintendo DS</a></li>
<hr />
<li><a href="<?php {echo $url . "&game_id=9&platform_id=5";} ?>">Nintendo Wii</a></li>
<hr />
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Javascript 变量在页面重新加载之间不会持续存在。
您必须将
或者
Javascript variables do not persist between page re-loads.
You will have to either
or
您可以提交当前的手风琴部分值,该值在您单击链接时打开,然后在加载页面(在 js 中)时从请求中读取。
默认情况下(对于第一页加载),默认值可以表示您需要加载第一部分。
当您通过脚本手动打开特定部分时,您可能需要手动操作 css。
You can submit the current accordion section value which is open when you click the link and subsequently readit from request when you load the page (in js).
By default (for the first page load), the default value can signify that you need to load the first section.
You might need to manipulate the css manually when you open a particular section manually via script.