JavaScript 中的 {0} 是什么意思
在这个答案的代码中:
$.validator.addMethod('lessThanEqual', function(value, element, param) {
return this.optional(element) || parseInt(value) <= parseInt($(param).val());
}, "The value {0} must be less than {1}");
{ 的含义是什么0}
和 {1}
? Javascript 中定义这些参数替换的经验法则是什么?
因此,根据评论,我想进一步询问以便在此处传递{0}和{1}。
我必须使用验证函数 lessThanEqual 的语法是什么。
谢谢
In the code from this answer:
$.validator.addMethod('lessThanEqual', function(value, element, param) {
return this.optional(element) || parseInt(value) <= parseInt($(param).val());
}, "The value {0} must be less than {1}");
What is the meaning of {0}
and {1}
? What is the rule of thumb in Javascript to define those parameter replacements?
So based on the comments, I want to further ask in order to pass {0} and {1} here.
What is the syntax I have to use for validation function lessThanEqual.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有“特殊”含义,它们只是验证器插件在显示消息时替换的标记,以数字方式引用规则的参数。
具体来说,这种情况发生在插件中:
因此
{0}
引用第一个参数,{1}
引用第二个参数,依此类推。这是格式函数 jQuery.validate 1.7 中的格式:There isn't a "special" meaning, they're just tokens that the validator plugin replaces when displaying the message, numerically referring to the parameters for the rule.
Specifically, this is happening in the plugin:
So
{0}
refers to the first parameter,{1}
the second and so on. Here's that format function as it is in jQuery.validate 1.7:我认为这是验证器插件特定的模板语法,用于将
{0}
绑定到实际值,将{1}
绑定到“所需”值。I think it's validator plugin specific templating syntax to bind
{0}
to the real value and{1}
to the "desired" value.它们是占位符。在使用验证器的代码中,{0} 和 {1} 被替换为实际值。
They are placeholders. In the code that uses the validator, {0} and {1} are replaced by actual values.
它们没有特殊含义,但用作格式占位符,例如:
They have no special meaning, however they are used as format placeholders, for example: