我試圖將numbers
設置爲與digits
相等。 我該怎麼做?我試過'numbers' : digits
但它不起作用。使用變量外部函數
// Checks if the checkbox is checked or not
$('#digits').change(
function(){
if ($(this).is(':checked')) {
digits = true;
} else {
digits = false;
}
});
// When the button "apply" is pressed it sets numbers equal to digits and calls the function test
$(document).ready(function(){
$('#apply').test({
'numbers': digits // This is where I'm stuck
});
});
(function($){
var methods = {
init : function(options, callbacks) {
var settings = $.extend({
'numbers': true,
}, options);
...
...
...
etc
$.fn.test= function(method) {
alert("SUCCESS");
...
...
};
})(jQuery);
您的'.test()'調用只發生一次,當DOM第一次加載時,它將使用當時的數字值。當'.change()'處理程序運行時,它不會對先前完成的任何操作產生任何影響。 – Barmar