2010-04-21 86 views
1

我有了這個字符串變量:如何從HTML字符串中刪除代碼?

<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

如果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

4

也許這樣?

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

我可能前後更多的HTML追加。有沒有辦法在這個特定的段落中找零?我只想擺脫關閉按鈕。任何方式通過onclick =「window.close()」來完成它? – TruMan1 2010-04-21 01:21:16