我有一個我從未遇到過的問題。我想簡單地在另一箇中添加一個div。我首先使用開發者控制檯進行測試。 我得到我想包含另一個div的元素,並在控制檯中正確打印元素。 後來我做到以下幾點:innerHtml無法在另一個內部打印我的div
document.getElementById("ctiGlobalContainer").innerHtml += '<div id="ctiContentPanel" state="displayed" style="z-index: 10000;right: 0;top: 50px;height: 100%;width: 200px;position: fixed;margin: 0;"></div>'
我得到以下結果:
"undefined<div id="ctiContentPanel" state="displayed" style="z-index: 10000;right: 0;top: 50px;height: 100%;width: 200px;position: fixed;margin: 0;"></div>"
爲什麼不確定的表現?而div不包括在內...
這不是一個用innerHTML在你的頁面中添加HTML的最佳方式,請使用jQuery或,參見'.appendChild()'函數:http://stackoverflow.com/questions/14004117/create-div-and-append-動態分區 –