1

我正在使用一个名为 pages 的 ajax,并试图使浏览器的“后退”和“前进”按钮工作。我尝试使用 ben alman 的插件,因为它似乎是最受欢迎的,但目前对我不起作用。我想知道问题是什么。我很确定这是我不理解的代码中的简单内容,所以请帮忙。我将向您展示每个代码:):

这些是处理程序:

<li><a href="#" class="ceni">примерни цени</a></li>
<li><a href="#" class="karieri">кариери</a></li> 

这是我的 javascript,它调用页面出现而不重新加载整个页面(ajax):

$('.ceni').click(function(){             
    $.ajax({
    url: 'pages/ceni.php',
    success: function(response) {
    $("#pages").html(response);
    }
     });    
  });



  $('.karieri').click(function(){           
    $.ajax({
    url: 'pages/karieri.php',
    success: function(response) {
    $("#pages").html(response);
    }
     });        
  });

这些是本阿尔曼的代码:

<script type="text/javascript" language="javascript">

$(function(){

  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('.bbq-default')
  };

  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  $(window).bind( 'hashchange', function(e) {

    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();

    // Remove .bbq-current class from any previously "current" link(s).
    $( 'a.bbq-current' ).removeClass( 'bbq-current' );

    // Hide any visible ajax content.
    $( '.bbq-content' ).children( ':visible' ).hide();

    // Add .bbq-current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );

    if ( cache[ url ] ) {
      // Since the element is already in the cache, it doesn't need to be
      // created, so instead of creating it again, let's just show it!
      cache[ url ].show();

    } else {
      // Show "loading" content while AJAX content loads.
      $( '.bbq-loading' ).show();

      // Create container for this url's content and store a reference to it in
      // the cache.
      cache[ url ] = $( '<div class="bbq-item"/>' )

        // Append the content container to the parent container.
        .appendTo( '.bbq-content' )

        // Load external content via AJAX. Note that in order to keep this
        // example streamlined, only the content in .infobox is shown. You'll
        // want to change this based on your needs.
        .load( url, function(){
          // Content loaded, hide "loading" content.
          $( '.bbq-loading' ).hide();
        });
    }
  })

  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );

});

$(function(){

  // Syntax highlighter.
  SyntaxHighlighter.highlight();

});

</script>

注意:我不是专家什么的,所以请尽可能简单地与我交谈。非常感谢 :)

4

1 回答 1

1

BBQ插件不会神奇地使后退和前进按钮起作用。BBQ 插件只是让更改浏览器哈希变得更容易(并且还支持多个哈希值)。您仍然需要自己更改哈希。

在此处阅读有关哈希的更多信息....

https://developers.google.com/tv/web/articles/location-hash-navigation

于 2012-08-29T12:49:10.157 回答