0
感謝jQuery,我得到了一個XHTML頁面(存儲在我的計算機上)的url,我想解析這個頁面,然後刪除我的XML的項目。用jQuery解析XHTML頁面,刪除元素並附加到div
我的XHTML頁面
<html>
...
<exampleXML>
<dataset>a</dataset>
<dataset>b</dataset>
<dataset>c</dataset>
</exampleXML>
...
</html>
我的jQuery代碼
var url_val = $("#xhtml_page").val();
$.get(url_val, function(data) {
$(data).find("dataset").each(function() {
if ($(this).text() == "a"){
$(this).remove();
}
});
$("#body-tmpl").html('<div id="id_container"></div>');
$("#id_container").html($(data));
});
當我的項目被刪除我會在一個div送我的新的XHTML的內容。
但不幸的是,我無法刪除XHTML元素(例如a)並將新頁面放入div中。這是最好的解決方案?
在嘗試刪除項目之前,我把我的XHTML放在了iframe中。
<iframe frameborder="0" style="width:100%; height:100%;" src="XHTMLfile.html">
#document<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head> … </head>
<body style="overflow: hidden; margin: 0px; font: 11px sans-serif; cursor: auto;">
<img id="hiddenImage" style="display:none" src="http://soft.sourceforge.net /img/hidden.png"></img>
<img id="loadingImage" style="display:none" src="http://soft.sourceforge.net /img/loading.gif"></img>
<img id="logo" style="display:none" src="http://soft.sourceforge.net/img/logo.png"> </img>
<noscript> … </noscript>
<div style="display:none"> … </div><div style="position: absolute; top: 1%; right: 2%; text-align: right;"> … </div>
<input type="button" value="x" style="position: fixed; visibility: visible; right: 10.5px; top: 492.333px;"></input>
<canvas width="1000" height="700"></canvas>
<div style="position: absolute; top: 0px;"> … </div>
</body>
</html>
</iframe>
現在我有,當我把它放在一個div:
<div id="id_container" style="width:1000px; height:700px;">
<meta charset="utf-8">
</meta><link href="http://soft.sourceforge.net/img/favicon.ico" rel="shortcut icon">
</link><img id="hiddenImage" style="display:none" src="http://soft.sourceforge.net/img/hidden.png"></img>
<img id="loadingImage" style="display:none" src="http://soft.sourceforge.net/img/loading.gif"></img>
<img id="logo" style="display:none" src="http://soft.sourceforge.net/img/logo.png"></img>
<noscript> … </noscript>
<div style="display:none">
… </div>
</div>
謝謝,但我有一個問題,因爲我的新XHTML是在div但內容沒有顯示。我認爲這是因爲我沒有標籤'
'。它已被刪除。 – Tof你能舉個例子說明你目前的結果是怎樣的以及你想要的結果應該是什麼樣子? – obecker