我在我的脚本中使用锚标记,这样当我回到页面时,我可以保存我所在的位置。问题是它仅在我单击链接时才有效。当我刷新页面或返回它时它不会。我没看到什么?信不信由你……这是 Chrome 的一个问题 - 它实际上在 IE 中运行良好!!!(我不敢相信我刚才这么说)
function parseXML(xml)
{
//find every Category and print the title
var output = '';
var ms = 0;
$(xml).find("category").each(function()
{
output += '<h3>' +$(this).find("title").text() + '<a name="m' + (ms+1) + '"></a> </h3> ' ;
var div = '<div>';
output += '<ul>';
$(this).find('items > item').each(function() {
var text = $(this).find("text").text();
var slink = $(this).find("link").text();
output += "<li class='subLink' src='"+ slink + "'><a href='#m"+ms+"'>" + text + "</a></li>";
});
output += '</ul>';
ms++;
});
var icons = {
header: "ui-icon-circle-arrow-e",
activeHeader: "ui-icon-circle-arrow-s"
};
var hashNum = 0;
if (window.location.hash != ''){
hashNum = parseInt(window.location.hash.replace("#m", ""));
};
$('<div>')
.attr('id','accordionSub')
.html(output)
.appendTo('#accordionSubB').delay(1).queue(function(){
$( "#accordionSub" ).accordion({
heightStyle: "content",
collapsible: true,
icons: icons,
active: hashNum
});
});
}
输出:
<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons ui-state-hover"
role="tab" id="ui-accordion-accordionSub-header-22" aria-controls="ui-accordion-accordionSub-panel-22"
aria-selected="false" tabindex="-1">
<span class="ui-accordion-header-icon ui-icon ui-icon-circle-arrow-e"></span>Pressure Transducers
<a name="m23"></a>
</h3>