我有我的導航菜單按鈕下面的代碼:保留當前導航按鈕活躍
div onmouseover=\"changeBGColor(this,'#b90707');changeColor(this,'#fff');\" onmouseout=\"changeBGColor(this,'');changeColor(this,'#333');\" onClick="" class='navbtn'>Entry /div
而下面的代碼,以保持元素活躍:
$('.navbtn').each(function(){
var path = window.location.href;
var current = path.substring(path.lastIndexOf('/')+1);
var url = $(this).attr('onClick').substring(path.lastIndexOf('/')+18,$(this).attr('onClick').length-1);
if(url == current){
changeBGColor(this,'#b90707');changeColor(this,'#fff');
$(this).onmouseout = '';
$(this).onmouseover= '';
};
});
元素保持活躍直到我將鼠標移到元素上。我想保持活躍隨時無論在哪裏我移動鼠標..似乎正在改變在onmouseout
處理程序的背景色
爲什麼你設置'mouseout'事件可言,如果你不需要它?請不要在元素屬性中使用內聯處理程序。它使代碼難以維護。 – feeela