2015-04-01 67 views
0

例如,我想將連鎖過程分配給不同的變量,並在不同的條件下使用它們。如何將連鎖函數分配給jQuery中的變量

var disable_btn = true; 
var button_me = $('#contents.getsamplekit .sample-form .form #submit-btn-freeSample-me'); 
var button_disabled = button_me.attr("disabled",true).css("background","red"); // need to add more functions. 
var button_enabled = button_me.removeAttr("disabled").css("background","green"); // need to add more functions here as well. 
(disable_btn) ? button_disabled : button_enabled; 
] 

回答

0

您在分配變量時調用函數,而不是在測試disable_btn時調用該函數。如果你想等待,你必須定義一個新的功能:

function button_disable(button) { 
    button.attr("disabled", true).css("background", "red"); 
} 
function button_enable(button) { 
    button.removeAttr("disabled").css("background","green"); 
} 
(disable_btn ? button_enable : button_disable)(button_me); 
相關問題