如何从HTML字符串中删除代码?

时间:2010-04-21 01:15:59

标签: javascript jquery regex

我有一个包含此字符串的变量:

<DIV><SPAN style="FONT-FAMILY: Tahoma; FONT-SIZE: 10pt">[If the confirmation is active the subscriber will receive this email after succesfully confirming. If not, this will be the first and only email he will receive.]</SPAN></DIV>
<p align=center>
    <input class=fieldbox10 type = 'button' name = 'button' value = 'Close' onclick = "window.close()">
</p>

如何通过Javascript(或jQuery)删除下面的字符串而不用担心空格?

<p align=center>
    <input class=fieldbox10 type = 'button' name = 'button' value = 'Close' onclick = "window.close()">
</p>

2 个答案:

答案 0 :(得分:4)

也许这个?

$(html).remove('p');

答案 1 :(得分:2)

如果你的var是myString,你可以这样做:

var temp = $("<div />").append(myString);
temp.find('p:has(input[value=Close])').remove('p');
myString = temp.html();​

You can see a working demo here