1
有沒有更好的方法將動態文本注入到除下面指定的代碼之外的html字符串中?在一個字符串內執行javascript函數
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;
}
'eval' ==='evil' –