我已经创建了一个包含以下内容的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 –