0
如何獲取一個字符串並在IE中使用它創建一個html片段。這在非ie瀏覽器中正常工作。在IE中從一個字符串創建一個範圍或html片段
var str = "<div>Foo</div>";
var range = document.createRange();
var frag = range.createContextualFragment(str);
var e = document.getElementById("element");
e.appendChild(frag);
'createContextualFragment'是不是一定需要考慮的廣泛採用innerHTML'的'。這裏有幾個使用文檔片段的答案,以避免使用直接的'innerHTML'方法得到的額外的div:http://stackoverflow.com/questions/814564/inserting-html-elements-with-javascript/814649 #814649和http://stackoverflow.com/questions/788614/ways-to-increase-performance-when-set-big-value-to-innerhtml/788661#788661 – 2010-01-22 19:56:57
innerHTML在主流瀏覽器中有不少特質。我真的很想知道如何使用符合W3C標準的代碼來做到這一點。 – Praesagus 2010-02-04 22:48:27