JQUERY 评估字符串

发布于 2024-07-29 16:50:36 字数 150 浏览 3 评论 0原文

我想在 jquery 中评估这个脚本:

var name = "Brian";
var txt = "This is your {name}";

任何人都可以帮助我吗? 我对这个非常菜鸟。

谢谢

I wanted to evaluate this script in jquery:

var name = "Brian";
var txt = "This is your {name}";

Anyone can help me? I'm very noob for this one.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清眉祭 2024-08-05 16:50:36

您可以连接:

var name = "Brian"; 
var txt = "This is your " + name;

或者您可以替换您的占位符

var name = "Brian"; 
var txt = "This is your {name}";

txt = txt.replace('{name}', name);

如果您想要更复杂的字符串格式,我建议您查看StringFormat jQuery 插件

You could concatenate:

var name = "Brian"; 
var txt = "This is your " + name;

or you could replace your placeholder:

var name = "Brian"; 
var txt = "This is your {name}";

txt = txt.replace('{name}', name);

If you want more sophisticated string formatting I recommend you to give a look to the StringFormat jQuery plugin

清音悠歌 2024-08-05 16:50:36

您可以使用

var txt = jQuery.validator.format("This is your {0}","Brian");

http://docs.jquery.com/Plugins/Validation/jQuery。验证器.format

you could use

var txt = jQuery.validator.format("This is your {0}","Brian");

http://docs.jquery.com/Plugins/Validation/jQuery.validator.format

苍暮颜 2024-08-05 16:50:36
var name = "Brian";  
var txt = "This is your "+name ;
var name = "Brian";  
var txt = "This is your "+name ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文