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