Javascript $(窗口).bind(';hashchange';,函数()--需要建议
这看起来是改变url的#值的最佳方法吗?它确实有效,但只是想知道是否有更好的方法Javascript $(窗口).bind(';hashchange';,函数()--需要建议,javascript,jquery,Javascript,Jquery,这看起来是改变url的#值的最佳方法吗?它确实有效,但只是想知道是否有更好的方法 $(function () { $(window).bind('hashchange', function () { var hash = window.location.hash; var map = { one: 1, two: 2, three: 3, four: 4
$(function () {
$(window).bind('hashchange', function () {
var hash = window.location.hash;
var map = {
one: 1,
two: 2,
three: 3,
four: 4
};
var hashValue = map[hash.substring(1)];
alert(hashValue);
});
});
您可以使用jquery.history插件: 它可以帮助您避免hashchange事件的一些交叉浏览器问题
function loadContent(hash) {
alert(hashValue);
// you can do some ajax here
}
$(document).ready(function() {
$.history.init(loadContent);
});
这个问题可能更适合于?如果你想迎合这些+新的浏览器,它在旧的IE中就不起作用了。你可以使用pushState,它看起来更漂亮