1

So i am using the Ben Alman history plug in to manage the back button functionality in my js/ajax application:

Read about the plugin here: JQuery Hashchange

It works fine on all of my links 'a' that contain an href but it doesn't not create a hash when an input button is clicked. How do I add this functionality? I have a lot of ajax forms that are process using buttons and need to make sure a hash is created on that event as well. Thank you for all your help.

4

1 回答 1

2

从文档

// Manually trigger the event handler.
jQuery(window).hashchange();

所以你需要有类似的东西

$('input#mybutton').click(function(){
    $(window).hashchange()

    // or directly changing the hash will trigger it too

    location.hash = 'somehash';        
}

我看过的大多数历史插件都只是在一个计时器上工作,所以每隔 50 毫秒左右,它们就会检查哈希值是否与以前相同。如果不是,他们会触发该事件。因此,当您直接更改 location.hash 时,它会识别它并触发事件。或者理论是这样的......

于 2012-02-22T22:38:22.047 回答