情况:<li class="active"><a href="#server1" data-toggle="tab">server1</a></li>
试用JS代码来添加到HTML中。
var li = document.createElement("li"); if(index==0){ li.className = "active"; } var a1 = document.createElement("a"); a1.href = "#server"+serverID; a1.id = "aServer"+serverID;
//a1.data-toggle = "tab";不能使用“.data-toggle”,不能识别“-”; a1.dataset.toggle = "tab";
a1.innerText = "server"+serverID; li.appendChild(a1); var tab = document.getElementById("navTab"); tab.appendChild(li);