[複製從jQuery - hashchange event這個答案]
我只是碰到了同樣的問題(缺乏hashchange事件在IE7)。一個適合我的目的的解決方法是綁定散列更改鏈接的click事件。
<a class='hash-changer' href='#foo'>Foo</a>
<script type='text/javascript'>
if (("onhashchange" in window) && !($.browser.msie)) {
//modern browsers
$(window).bind('hashchange', function() {
var hash = window.location.hash.replace(/^#/,'');
//do whatever you need with the hash
});
} else {
//IE and browsers that don't support hashchange
$('a.hash-changer').bind('click', function() {
var hash = $(this).attr('href').replace(/^#/,'');
//do whatever you need with the hash
});
}
</script>
Internet Explorer不是一個有效的瀏覽器... – genesis