我得到了下面的代碼:
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
如何是'UpdatePriceSubscribeButton'叫? – 2012-02-18 16:08:45
它在頁面加載和Ajax調用完成時調用。 – Banshee 2012-02-18 16:11:35
請求,請參閱Edit2 – Banshee 2012-02-18 16:12:42