锚标签无法在Chrome中使用
我在我的脚本中使用锚标签,这样当我回到页面时,我可以保存我所处的位置。 问题是它只在我点击链接时才有效。 当我刷新页面,或者回到它时,它没有。 我没看到什么? 信不信由你…这是Chrome的一个问题 – 它在IE中实际上运行正常!!!(我简直不敢相信我只是这么说)
function parseXML(xml) { //find every Category and print the title var output = ''; var ms = 0; $(xml).find("category").each(function() { output += '' +$(this).find("title").text() + '
' ; var div = ''; output += ''; $(this).find('items > item').each(function() { var text = $(this).find("text").text(); var slink = $(this).find("link").text(); output += "- " + text + "
"; }); output += '
'; 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", "")); }; $('') .attr('id','accordionSub') .html(output) .appendTo('#accordionSubB').delay(1).queue(function(){ $( "#accordionSub" ).accordion({ heightStyle: "content", collapsible: true, icons: icons, active: hashNum }); }); }
OUTPUT:
Pressure Transducers
在您的锚中使用id而不是名称。
HTML链接 – id属性id属性可用于在HTML文档中创建书签。
提示:书签不会以任何特殊方式显示。 它们对读者来说是不可见的。
示例HTML文档中具有id的锚:
Useful Tips Section
在同一文档中创建指向“有用提示部分”的链接:
Visit the Useful Tips Section
或者,从另一个页面创建指向“有用提示部分”的链接:
访问实用技巧部分
找到一个我必须添加的解决方案:
$(window).load(function(){ var hashNum = 0; if (window.location.hash != ''){ hashNum = window.location.hash.replace("#m", ""); console.log('hashNum: ' + hashNum); }; hashMenu = $("#m"+hashNum-1).offset().top; $('html,body').animate({ scrollTop: hashMenu }, 1000); });