我想在jquery中评估这个脚本:
var name = "Brian";
var txt = "This is your {name}";
任何人都可以帮助我吗?我非常喜欢这个。
由于
答案 0 :(得分:2)
你可以连接:
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插件
答案 1 :(得分:0)
var name = "Brian";
var txt = "This is your "+name ;
答案 2 :(得分:0)
你可以使用
var txt = jQuery.validator.format("This is your {0}","Brian");
http://docs.jquery.com/Plugins/Validation/jQuery.validator.format