相關turning Ajax Responsexml into HTML
我試圖使用XHR得到<select>
元素有幾個選項,並將其追加到<div>
,但使用importNode()
和appendChild()
我無法獲得呈現爲HTML元素的響應。相反,所有顯示的是選項的文本。
例如,這裏是我的xml:如何獲得XHR顯示的responseXML爲一個HTML元素(沒有的innerHTML)
<select>
<option value='1'>A</option>
</select>
結果頁面僅顯示文本A
而不是select
元素。爲什麼不呈現這些元素,以及什麼是正確導入它們的好方法(不使用innerHTML)?
小提琴: http://jsfiddle.net/9D9pD/2/
相關的JavaScript [我甚至嘗試adoptNode()
]:
function handleResponse() {
var xmlResponse = xmlHttp.responseXML,
root = xmlResponse.documentElement;
console.log(xmlHttp.responseText);
var i = document.importNode(root, true);
var a = document.adoptNode(root);
document.getElementById("import").appendChild(i);
document.getElementById("adopt").appendChild(a);
}
我學到了一些東西,感謝http://jsfiddle.net/9D9pD/4/ –