這看起來有點棘手,因爲Accordion API docs並不容易,activate()
功能看起來不像廣告那樣工作。
從您的問題,它聽起來像你想通過引用div ID打開手風琴部分。這是不可能的,您只能使用基於0的索引來標識節(例如,0 =第一節,1 =第二節等)。
話雖如此,這種做法將工作:
這樣定義鏈接:
<a href="10387904_Accordion_link_2.html?openAccordionId=0">Open first item</a>
<a href="10387904_Accordion_link_2.html?openAccordionId=1">Open second item</a>
<a href="10387904_Accordion_link_2.html?openAccordionId=2">Open third item</a>
在包含手風琴的頁面,使用下面的代碼來提取查詢字符串的ID和初始化有關部分的手風琴激活:
// Using the parseQueryString extension from
// http://paulgueller.com/2011/04/26/parse-the-querystring-with-jquery/
$.extend({
parseQuerystring: function() {
var nvpair = {};
var qs = window.location.search.replace('?', '');
var pairs = qs.split('&');
$.each(pairs, function (i, v) {
var pair = v.split('=');
nvpair[pair[0]] = pair[1];
});
return nvpair;
}
});
// Get the index of the section we want to open from the querystring.
var openAccordionId = parseInt($.parseQuerystring()["openAccordionId"]);
// Initialise the accordion with the active section defined.
var accordion = $("#accordion").accordion({ active: openAccordionId });
// Note: for some reason, the following does not work:
// var accordion = $("#accordion").accordion();
// accordion.activate(openAccordionId);
你有沒有運氣在我的答案中應用解決方案? –