关于 MS jquery.validate.unobtrusive.js 文件的问题
我正在尝试更多地了解如何
jquery.validate.unobtrusive.js
文件有效。
我对下面缩写的开头语法感到困惑...
(function ($) {
var $jQval = $.validator,
adapters,
data_validation = "unobtrusiveValidation";
function setValidationValues(options, ruleName, value) {
options.rules[ruleName] = value;
if (options.message) {
options.messages[ruleName] = options.message;
}
}
... more stuff (deleted)
}(jQuery));
问题
- jquery.validate.unobtrusive.js 加载并具有一个采用名为 $ 的参数的函数。这是正确的吗?
- 我不习惯将 $ 作为参数名称,但我认为它只是一个参数,$ 没有特殊意义?
- 我还没有看到 (function(){}(jQuery));句法。这是在做什么?
感谢您的任何见解!
I am trying to learn more about how the
jquery.validate.unobtrusive.js
file works.
I am confused by the opening syntax which I have abbreviated below...
(function ($) {
var $jQval = $.validator,
adapters,
data_validation = "unobtrusiveValidation";
function setValidationValues(options, ruleName, value) {
options.rules[ruleName] = value;
if (options.message) {
options.messages[ruleName] = options.message;
}
}
... more stuff (deleted)
}(jQuery));
Questions
- jquery.validate.unobtrusive.js loads and has a function that takes a parameter named $. Is this correct?
- I am not used to seeing $ as a parameter name, but I assume it is simply a parameter and $ has no special significance?
- I have not seen the (function(){}(jQuery)); syntax. What is this doing?
Thanks for any insight!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我在阅读有关编写 jQuery 插件的内容时找到了这个问题的答案。
http://docs.jquery.com/Plugins/Authoring
传递给函数的 $ 是 jQuery本身被传递给一个函数,这样命名空间冲突就不会发生(这主要回答了我的问题 1-3)。
Ok, I have found the answer to this while reading about authoring jQuery plugins.
http://docs.jquery.com/Plugins/Authoring
The $ passed to the function is jQuery itself being passed to a function so that namespace collisions won't occur (which mostly answers my questions 1-3).