除了下面指定的代码之外,有没有更好的方法将动态文本注入html字符串?
var code ='siteCode1';
html代码作为字符串:
existing: '<p>Log in with your'+ eval("siteVarObj('+code+').siteName") +'account</p>',
function siteVarObj(siteCode){
if(siteCode === 'siteCode1'){
this.siteName = 'google.com';
this.siteContactUsURL = '';
}else if(siteCode === 'siteCode2'){
this.siteName = 'stackoverflow.com';
this.siteContactUsURL = '';
}
return this;
}
Run Code Online (Sandbox Code Playgroud)
这应该工作得很好:
var code = 'siteCode1';
var myHTMLString = '<p>Log in with your '+ siteVarObj(code).siteName + ' account</p>';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42 次 |
| 最近记录: |