Javascript url jquery accordion中没有标签
下面是一个手风琴代码,它可以完美地工作。我不想使用hashtag,因为它破坏了我们当前的网站。有没有办法在accordion中使用无标签url? 我试过用?但是,当使用url访问手风琴时,它不起作用?这可能吗 所以我的想法是,当我有这样一个url时,能够打开手风琴: 从:test.htmlink1到:test.html?Link1,它不必是问号,我只是想试试看,它可以是除hashtag以外的任何东西。谢谢Javascript url jquery accordion中没有标签,javascript,jquery,html,Javascript,Jquery,Html,下面是一个手风琴代码,它可以完美地工作。我不想使用hashtag,因为它破坏了我们当前的网站。有没有办法在accordion中使用无标签url? 我试过用?但是,当使用url访问手风琴时,它不起作用?这可能吗 所以我的想法是,当我有这样一个url时,能够打开手风琴: 从:test.htmlink1到:test.html?Link1,它不必是问号,我只是想试试看,它可以是除hashtag以外的任何东西。谢谢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
var $accordion = $("#accordion").accordion({active: false, collapsible: true}),
hashId = 0;
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="?' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
}
});
</script>
</head>
<body>
<div id="accordion">
<h3><a href="?link1">Link1</a></h3>
<div>content</div>
<h3><a href="?link2">Link2</a></h3>
<div>content</div>
</div>
</body>
</html>
您可以使用格式为test.html?section=Link1的url。您只需要停止使用散列,并提取queryString参数。生成的代码类似于:
<script type="text/javascript">
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function() {
var $accordion = $("#accordion").accordion({active: false, collapsible: true}),
hashId = 0,
section = getParameterByName('section');
if (section) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === section) {
hashId = i;
}
});
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="?' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
}
});
</script>
我不知道你的问题的答案,但它不是一个标签,它只是一个哈希、磅或数字符号。@Steve你明白我的意思,哈希、磅,我想我使用标签是因为twitter说哈希标签,谢谢你的更正,所以磅、数字符号等等。我不希望这是url。