-3

我试图让 js 脚本使用 for 循环创建一些标签,但我收到错误 Object # has no method '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 = "&times;";

 }


  /* XML Structure:
      <div class="tab">
        Dashboard
        <button type="button" class="closetab">&times;</button>
      </div>
                                                                    */
}
4

2 回答 2

3

容器没有 creatElement 方法

文件有

var elem= document.createElement("div");

container.appendChild(elem);
于 2013-05-10T19:29:50.920 回答
0

利用:

document.createElement("div");
于 2013-05-10T19:30:12.187 回答