我有一个循环,其中我试图添加这行代码
实施例
<div class="wb-share" data-wb-share='{"pnlId": "pnl1"}'></div>
我的实际代码是
var share = "<div class=\"wb-share\" data-wb-share='{\"pnlId\": \"pnl" + Id + "\"}'></div>";
呈现为
<div class="wb-share" data-wb-share="{"pnlId": "pnl206259534"}"></div>
答案 0 :(得分:0)
使用innerHTML
方法并将这些字符转义,请检查此代码段的浏览器检查器。
var share = "<div class=\"wb-share\" data-wb-share='{\"pnlId\": \"pnl1\"}'></div>";
document.getElementById('app').innerHTML = share
&#13;
.wb-share{ background: #000; width: 100px; height: 100px;}
&#13;
<div id='app'></div>
&#13;