我试图让一个js脚本用for循环创建一些标签,但我得到错误对象#没有方法'createElement'
它的功能如下:
function tabListRefresh() {
// Get Container
var container = document.getElementById("tabListContainer");
// Clear container
container.innerHTML = "";
// Create tags
for( var k=0; k<tabs.length; k++ ) {
// Create div tag
var div = container.createElement("div");
div.setAttribute("class", "tab");
// Include title into tag
div.innerHTML = tabs[k][0] + " ";
// Create closetab-icon
var closebtn = div.createElement("button");
div.setAttribute("type", "button");
div.setAttribute("class", "closetab");
closebtn.innerHTML = "×";
}
/* XML Structure:
<div class="tab">
Dashboard
<button type="button" class="closetab">×</button>
</div>
*/
}
答案 0 :(得分:3)
Container没有creatEelement方法
文件有它
var elem= document.createElement("div");
container.appendChild(elem);
答案 1 :(得分:0)
使用:
document.createElement("div");