2012-02-18 9 views
1

こんにちは!jqueryでmouseoutイベントのバインドを解除しますか?

は、私は、次のコードを得た:

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'}); 
    } 
}; 

これに伴う問題は、ときに、クラスONMOUSEOUT _userPriceSubscribeが1に設定された場合でも、変更されることがありますか?

私がここでやろうとしているのは、jqueryを使ってクライアント側の現在のクラスとホバークラスを変更することです。

Edit1:私も$( "#btUpdatePriceSubscribing")を実行しました。unbind( 'omouseenter mouseleave');それはここに推薦している: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'が呼び出されますか? –

+0

ページロード時およびAjax呼び出しが行われたときに呼び出されます。 – Banshee

+0

pleas、Edit2を参照 – Banshee

答えて

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

最後の '}' - > '});'。 –

1

イベント名はmouseenterないomouseenterです。

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

omouseenterは、カスタムイベントでない限り、あなたはこの行を変更したいと思う

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

関連する問題