0
我有一個來自this網站的jQuery手風琴,並且爲我的目的進行了編輯,但手風琴只適用於Firefox(不是Safari或Chrome),而且Cookie設置不正確。jQuery手風琴和餅乾問題
這是jQuery的:
function initMenus() {
$('#sidebar .letter_index').hide();
$.each($('#sidebar .letter_index'), function() {
var cookie = $.cookie(this.id);
if (cookie === null || String(cookie).length < 1) {
$('#sidebar .letter_index:first').show();
} else {
$('#' + this.id + ' .' + cookie).next().show();
}
});
$('#sidebar .letter_head').click(function() {
var checkElement = $(this).next();
var parent = this.parentNode.parentNode.id;
if ((checkElement.is('.letter_index')) && (!checkElement.is(':visible'))) {
$('#' + parent + ' .letter_index:visible').slideUp('normal');
if ((String(parent).length > 0) && (String(this.className).length > 0)) {
// not working
$.cookie(parent, this.className);
}
checkElement.slideDown('normal');
return false;
}
}
);
}
$(document).ready(function() {initMenus();});
這是怎麼我的HTML的外觀(樣本項目):
<div id="sidebar">
<h2 class="letter_head"><a href="#" class="ABC">ABC</h2>
<ul class="letter_index">
<li>Abc</li>
<li>Bcd</li>
</ul>
</div>
我找不到爲什麼腳本將不會在Safari中正常工作的問題和Chrome。
我也不知道如何告訴它使用h2
內的a
作爲cookie值。 (目前該Cookie設置爲$.cookie(parent, this.className);
,其產生的Cookie名稱爲container
(#sidebar以上的div)和值letter_head
,它需要像'sidebar'和'ABC','DEF'等。
提前感謝!
輝煌,謝謝! :)餅乾現在完美運行,但手風琴在Chrome,Opera或Safari中仍然無法使用。編輯:我只注意到小提琴的作品,但我的腳本沒有。這個問題必須在我的PHP的某個地方產生菜單,所以我正在研究:) – rayne 2010-05-06 07:05:09
對不起,遲到的答覆;我現在包括像/ en/about /等URL重寫到我的網站和菜單不再工作了,因爲Cookie設置爲特定的路徑。如何在不考慮路徑的情況下設置cookie,這樣菜單會在整個站點上再次運行? – rayne 2010-05-10 12:10:26
嗨,Rayne!嘗試改變這行'$ .cookie(sidebar.attr('id'),headClassName);'這個'$ .cookie(sidebar.attr('id'),headClassName,{path:'/'});' – Mottie 2010-05-10 20:56:30