我已經創建了一個包含以下內容的JavaScript文件:是否可以調用嵌套在另一個函數中的函數?
(function ($) {
//Define a Drupal behaviour with a custom name
Drupal.behaviors.jarrowDynamicTextfieldValidator = {
attach: function (context) {
//Add an eventlistener to the document reacting on the
//'clientsideValidationAddCustomRules' event.
$(document).bind('clientsideValidationAddCustomRules', function(event){
//Add your custom method with the 'addMethod' function of jQuery.validator
//http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage
jQuery.validator.addMethod("typeValidator", function(value, element, param) {
...bunch of code here...
}, jQuery.format('Field can not be empty'));
});
}
};
})(jQuery);
我想要做的就是添加一個變化監聽器選擇框,這樣當選擇更改它會調用這個確認功能。我不確定是否可以這樣做,因爲驗證代碼被隱藏在幾個函數中。這可能嗎?
哪些功能特別是你想要打電話? – Kristian
是的,你絕對可以做到這一點...以許多不同的方式。檢查了這一點:http://stackoverflow.com/questions/500431/javascript-variable-scope –