2013-03-14 39 views
1

我在脚本中使用了锚标签,因此当我返回页面时,我可以保存我所处的位置。问题是只有当我点击链接时才有效。当我刷新页面,或者回到它时,它不会。我没有看到什么?信不信由你......这是Chrome存在的问题 - 它实际上在IE罚款!!!(我不能相信我刚才说的)在Chrome中不起作用的锚标签

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 
      }); 
}); 

} 

OUTPUT:

<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> 
+0

有没有什么办法可以真正向我们展示了什么问题? – 2013-03-14 16:12:14

+0

不幸的是,除非你知道某处我可以上传页面进行查看。 – tree 2013-03-14 16:38:43

+0

http://jsfiddle.net/LgZej/2/它并不真正告诉你浏览器正在做什么我知道 – tree 2013-03-14 16:52:52

回答

0

找到一个解决办法,我不得不补充一点:

$(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); 

    }); 
0

在你的锚中使用id来代替名字。

HTML链接 - id属性 id属性可用于在HTML文档中创建书签。

提示:书签不以任何特殊方式显示。它们对读者是不可见的。

例 与HTML文档中的ID的锚:

<a id="tips">Useful Tips Section</a> 

创建同一文档内的链接,“有用的提示一节”:

<a href="#tips">Visit the Useful Tips Section</a> 

或者,创建一个链接到另一页的“有用提示部分”:

<a href="http://www.w3schools.com/html_links.htm#tips"> 

访问有用的提示一节

http://www.w3schools.com/html/html_links.asp

+0

它不适用于Chrome或IE。 – tree 2013-03-14 16:38:02