技术实践

ES6模板字符串拼接HTML

ES6模板字符串拼接HTML

羊先生的头像
羊先生2022.03.02 · 1 分钟阅读 · 47 阅读
ES6模板字符串拼接HTML封面
文章正文还需 1 分钟

模板字符串拼接

js 复制代码
let html = `【<input onblur="handleBlurInput(this,${JSON.stringify(item).replace(/\"/g, '\'')})" validate="${JSON.stringify(item)}" contenteditable="true" value="${item.value}" placeholder="${item.placeholder}">】`;

普通拼接

js 复制代码
html = '<input onblur="handleBlurInput(' + JSON.stringify(item).replace(/\"/g, '\'') + ')"/>'
js 复制代码
'<a  id="adw" href="javascript:void(0)" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  
    onclick="InLocation(' + row.x + ',' + row.y + ',' + row.ID + ',\'' + temp + '\');">
    定位</a>
    &nbsp|&nbsp
    <a  id="a" href="javascript:void(0)" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  onclick="myAjax(' + row.ID + ');">
    删除</a>