gpt4 book ai didi

jquery 从链接打开 Accordion

转载 作者:行者123 更新时间:2023-12-01 07:58:20 25 4
gpt4 key购买 nike

我做错了什么。 Accordion 可以工作,但是当我尝试从外部链接(fx.mysite.com/mypage.php#2)打开它时 - 它不会打开 Accordion !

我的标题是:

<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#accordion").accordion({
active: false,
collapsible: true,
autoHeight: false,
navigation: true,
header: '.menuitem'
});
$(".menuitem").click(function(event){
window.location.hash=this.hash;
});
});
</script>

我的html是:

  <div id="accordion">
<a class="menuitem" href="#1">Header 1</a>
<!-- accordion panel --><div>
CONTENT 1</>
<!-- end accordion panel --></div>
<a class="menuitem" href="#2">Header 2</a>
<!-- accordion panel --><div>
CONTENT 2</>
<!-- end accordion panel --></div>
<!-- end accordion -->

最佳答案

这是工作代码 - Jsfiddle Link

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<script>
$(document).ready(function() {

$("#accordion").accordion({
active: false,
collapsible: true,
autoHeight: false,
navigation: true,
header: 'a.menuitem'
});

$(".menuitem").click(function(event){
window.location.hash=this.hash;
});

//get the hash value
var locationHash = window.location.hash;

//split the value
var hashSplit = locationHash.split('#');

//get the tab number
var currentTab = hashSplit[1];

window.setTimeout(function(){
//open the tab for the current hash
$("#accordion").accordion({ active: parseInt(currentTab)-1 });
}, 1000);

});
</script>


</head>



<body>

<div id="accordion">
<a class="menuitem" href="#1">Header 1</a>
<!-- accordion panel -->
<div>
CONTENT 1
</div>

<a class="menuitem" href="#2">Header 2</a>
<div>
CONTENT 2
</div>
<!-- end accordion -->
</div>

</body>
</html>

关于jquery 从链接打开 Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21932607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com