JS常量里面有变量
我知道我可以在 PHP 中做到这一点,但我不记得名称或执行方法,所以我只会解释它是什么,当有人告诉我它是如何调用时,我会更新这个问题。 我有一些错误消息定义为 JavaScript 上的常量,但是,其中一些消息需要包含动态部分,如下例所示。
"The username must be between 4 and 20 characters"
在 php 中,如果我没有记错的话,有一些选项可以以某种方式存储该字符串,当调用时,它将用调用时提供的数据替换变量。 我想在 javascript 上执行此操作,例如:
config['string',vars]
并让 javascript 在字符串中插入这些变量,以便对其进行自定义。 哇,这一定是我问过的最糟糕的问题了!抱歉缺乏信息,周日我有点脑残。
I know I'm able to this in PHP, but I can't remember the name or the way to do it, so I'll just explain what it is, and when someone tells me how it's called I'll update this question.
I have some error messages defined as constants on javascript, however, some of those messages need to contain dynamic part as in the following example.
"The username must be between 4 and 20 characters"
In php, If I'm not mistaken there was some option for storing that string in a way that when called it would replace the variables with the data provided on the call.
I want to do that on javascript, something like:
config['string',vars]
And have javascript insert those vars inside the string so it's customized.
Wow, this must be the worst question I've made! I'm sorry for the lack of information, I'm kinda braindead on Sundays.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种行为没有内置功能,但您可以定义它 您自己或使用各种框架中现有的框架。
There isn't built-in functionality for such a behavior, but you can define it yourself or use the ones existing in various frameworks.