2
我有XML字符串表示一些HTML標籤。我想選擇一些XML並將其導入到HTML。導入XML到HTML
目前我在做什麼一個例子:
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div><p>som text</p></div>
<h1>hi there</h1>
<button>click</button>
<script>
xml = '<?xml version="1.0" encoding="utf-8"?><root><html><a href="#">the new link</a></html></root>';
$xml =$($.parseXML(xml));
$('button').on('click',function(){
var content = $xml.find('html:first').contents();
content.appendTo('body');
});
</script>
</body>
</html>
的代碼應該添加在頁面的最後一個鏈接,但我只能看到文字,它不是鏈接。沒有HTML標籤的作品。
我用另一個庫要做到這一點,而不是像jQuery的https://github.com/jindw/xmldom,但結果是一樣的。 更新:這是jsfiddle鏈接:http://jsfiddle.net/V4gHz/
.html()不適用於xml文檔。因爲它裏面使用了innerHTML函數。 –
'.text()'怎麼辦? – Jashwant
nope。在所有 –