嗨,我正在尝试从特定字符串中删除所有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
必须用引号括起来。 - Bhushan Kawadkar'</p>'/g
) 看起来很奇怪。我认为那根本行不通。 - Alvaro Montoro