【发布时间】:2015-10-09 13:06:43
【问题描述】:
您好,我正在尝试从显示错误的特定字符串中删除所有 html 标记。
这是我的字符串:
<p>Hi there</p> ~ wifi free <p>this is test</p> ~ breakfast free <p>This is another test</p>
我的 jQuery 代码在这里:
var item = <p>Hi there</p> ~ wifi free <p>this is test</p> ~ breakfast free <p>This is another test</p>;
item = item.replace(/~/g, '');
item = item.replace(/<p>/g, '');
item = item.replace('</p>'/g, '');
var splitArray = item.split('<br />');
var l = splitArray.length;
for (var i = 0; i < l; i++) {
out = out + "<li><span class='sp_icon sp_star_icon'></span> "
+ splitArray[i].trim() + "</li>";
}
console.log(item);
【问题讨论】:
-
该错误是否与您的第一个字符串未用引号括起来的事实有关?或者这不是它在您的代码中的实际外观?请确保您发布的正是您使用的内容。并告诉我们错误。
-
您的变量
item必须用引号引起来。 -
第三个替换(
'</p>'/g)也很奇怪。我认为这根本行不通
标签: javascript jquery