我想在我的javascript代码中调用click方法中的逻辑。我怎么称呼这种方法?
(function($) {
window.numberArray = [],
window.phoneNumber = '',
window.updateDisplay,
window.numberDisplayEl,
window.inCallModeActive,
window.dialpadButton = $('div#dialpad li'),
window.dialpadCase = $('div#dialpad'),
window.clearButton = $('#actions .clear'),
window.callButton = $('#actions .call'),
window.actionButtons = $('#actions'),
window.skipButton = $('#actions .skip'),
window.numberDisplayEl = $('#numberDisplay input');
$('div#actions li.clear').click(function() {
debugger;
enableCallButton();
enableDialButton();
clearPhoneNumber();
removeReadOnlyInput();
changeHangUpIntoClear();
updateDisplay();
checkDisplayEl();
disableInCallInterface();
});
})(jQuery);
答案 0 :(得分:0)
您可以从代码内部创建包含所需函数的全局变量。
//The object with the functions
var functions = {};
(function($) {
window.numberArray = [],
window.phoneNumber = '',
window.updateDisplay,
window.numberDisplayEl,
window.inCallModeActive,
window.dialpadButton = $('div#dialpad li'),
window.dialpadCase = $('div#dialpad'),
window.clearButton = $('#actions .clear'),
window.callButton = $('#actions .call'),
window.actionButtons = $('#actions'),
window.skipButton = $('#actions .skip'),
window.numberDisplayEl = $('#numberDisplay input');
//Here you set the property action with the function call
functions.action = function (){
debugger;
enableCallButton();
enableDialButton();
clearPhoneNumber();
removeReadOnlyInput();
changeHangUpIntoClear();
updateDisplay();
checkDisplayEl();
disableInCallInterface();
}
$('div#actions li.clear').click(function() {
functions.action();
});
})(jQuery);