它指向我
var T = document.createElement("table id=""+tableID+""");
我试图创建一个具有特定ID的表元素。知道发生了什么事吗?我以为我做了一个合适的逃脱序列。
答案 0 :(得分:3)
某些IE版本允许您在document.create中包含完整标记,但是浏览器之后的标准只接受标记名称。要设置ID,您可以直接设置属性或使用setAttribute
。
var T = document.createElement("table");
T.id=tableID;
或
var T = document.createElement("table");
T.setAttribute("id", tableID);
答案 1 :(得分:1)
这里的无效字符是空格。 document.createElement
仅将元素名称作为参数,元素名称不能包含空格。所以你应该首先创建elemnt,然后设置它的属性/属性。
var T = document.createElement('table');
T.id = tableID