2012-02-18 86 views
1

嗨!解除jQuery中的鼠標事件?

我得到了下面的代碼:

function UpdatePriceSubscribeButton() { 

    if (_userPriceSubscribe > 0) { 
     $("#btUpdatePriceSubscribing").removeClass("con"); 
     $("#btUpdatePriceSubscribing").addClass("conActive"); 
     $("#btUpdatePriceSubscribing").unbind('onmouseover').unbind('onmouseout'); 
    } 
    else { 
     $("#btUpdatePriceSubscribing").removeClass("conActive"); 
     $("#btUpdatePriceSubscribing").addClass("con"); 
     $("#btUpdatePriceSubscribing").mouseover(function() { this.className = 'conActive'}); 
     $("#btUpdatePriceSubscribing").mouseout(function() {this.className = 'con'}); 
    } 
}; 

這樣做的問題是,當將鼠標移開類將甚至改變如果_userPriceSubscribe設置爲1?

我在這裏試圖做的是改變當前類和懸停類在客戶端與jquery。

編輯1:我也試過$(「#btUpdatePriceSubscribeing」)。unbind('omouseenter mouseleave');正在這裏sugested:http://api.jquery.com/hover/

EDIT2:這工作:

function UpdatePriceSubscribeButton() { 

    if (_userPriceSubscribe > 0) { 
     $("#btUpdatePriceSubscribing").removeClass("con"); 
     $("#btUpdatePriceSubscribing").addClass("conActive"); 
     $("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave'); 
    } 
    else { 
     $("#btUpdatePriceSubscribing").removeClass("conActive"); 
     $("#btUpdatePriceSubscribing").addClass("con"); 

     $("#btUpdatePriceSubscribing").hover(function() { this.className = 'conActive' }, function() { this.className = 'con' }); 
    } 
}; 

但是,這是做這件事的好方法嗎?

BestRegards

+0

如何是'UpdatePriceSubscribeButton'叫? – 2012-02-18 16:08:45

+0

它在頁面加載和Ajax調用完成時調用。 – Banshee 2012-02-18 16:11:35

+0

請求,請參閱Edit2 – Banshee 2012-02-18 16:12:42

回答

0

這解決了我的問題:

function UpdatePriceSubscribeButton() { 

    if (_userPriceSubscribe > 0) { 
     $("#btUpdatePriceSubscribing").removeClass("con"); 
     $("#btUpdatePriceSubscribing").addClass("conActive"); 
     $("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave'); 
    } 
    else { 
     $("#btUpdatePriceSubscribing").removeClass("conActive"); 
     $("#btUpdatePriceSubscribing").addClass("con"); 

     $("#btUpdatePriceSubscribing").hover(function() { this.className = 'conActive' }, function() { this.className = 'con' }); 
    } 
}; 
1

會是有意義的建立一個的onmouseout /的onmouseover處理,看起來對於鼠標移出處理器內部的價格是多少?

$("#btUpdatePriceSubscribing").mouseover(function() { 
    if (_userPriceSubscribe > 0) { 
     this.className = "..." 
    } 
} 

(否則我不知道我得到你想要做什麼......)

+2

最後'}' - >'});'。 – 2012-02-18 16:14:29

1

事件名稱是mouseenter沒有omouseenter。所以,除非omouseenter是一個自定義事件,你會想改變這一行:

$("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave');

到:

$("#btUpdatePriceSubscribing").unbind('mouseenter mouseleave');