1
我试图每次更改URL时更新我的菜单按钮的状态。下面的代码是在我的按钮mouseleave
:URL更改后更改按钮的状态
$(document).ready(function() {
$("#btnAdd, #btnEdit").mouseleave(function(event) {
ActivateMenuButton();
});
});
function ActivateMenuButton() {
var currentURL = window.location.pathname;
//alert(currentURL);
//deselect current selected button
$("#btnAdd, #btnEdit").removeClass("buttonSelected");
//select menu button according to URL
if (currentURL.indexOf('Add') >= 0) {
$("#btnAdd").addClass("buttonSelected");
}
if (currentURL.indexOf('Ddit') >= 0) {
$("#btnEdit").addClass("buttonSelected");
}
}
有过的jQuery或javescript一种方法来检测时,页面的变化和射击上面的代码?
您可以尝试使用卸载事件:http://docs.jquery.com/Events/unload – cheesemacfly 2013-02-08 17:03:32