我的数据为
var data = '<template type="amp-mustache">
<div class="comment-item pull-left bottommargin10">
<div>
<span class="comment-user-logo pull-left">{{title}}</span>
<div class="pull-left margin-left-7">
<span class="comment-name">{{user.displayName}}</span>
<div class="comment-date">{{newDate}}</div>
<div class="comment-msg">{{message}}</div>
</div>
</div>
</div>
</template>';
当我尝试更换它时
var newData = data.replace('<template type="amp-mustache">','');
它抛出以下错误
data.replace is not a funtion
谁能帮帮我。谢谢。
最佳答案
您需要对多行字符串使用反引号。请参阅Template literals .
var data = `<template type="amp-mustache">
<div class="comment-item pull-left bottommargin10">
<div>
<span class="comment-user-logo pull-left">{{title}}</span>
<div class="pull-left margin-left-7">
<span class="comment-name">{{user.displayName}}</span>
<div class="comment-date">{{newDate}}</div>
<div class="comment-msg">{{message}}</div>
</div>
</div>
</div>
</template>`;
console.log(data.replace('<template type="amp-mustache">',''));
关于javascript - .replace 在 js 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44495854/