當條件返回true時,我有許多按鈕必須自行阻止。像打擊沒有工作。如何做到優雅?條件許多處理程序
$('#button1,#button2,#button3').click(function(event){
if(maintence_mode){
event.preventDefault(); // alerts can't be shown
}
});
$('#button1').click(function(){
alert('1');
});
$('#button2').click(function(){
alert('2');
});
$('#button3').click(function(){
alert('3');
});
更新: 我有完全類似下面現在不event.stopImmediatePropagation()
工作。我認爲,請求/isservicemode
需要一些時間......
var checkServiceMode = function(callback) {
$.get('/isservicemode', function(data){
callback(data.mode);
});
}
$('#button1,#button2,#button3').click(function(event){
checkServiceMode(function(modeon){
if(modeon) {
event.preventDefault();
event.stopImmediatePropagation();
return false;
}
});
});
怎麼樣一個簡單的返回FALSE; ?條件滿足時。 – SSA 2014-08-28 11:49:03