Javascript 使用JS向表中添加类名或id
假设这段代码使用DOM()创建一个带有plainJavaScript的表: 使用向元素添加属性,如下所示:Javascript 使用JS向表中添加类名或id,javascript,html,dom,setattribute,Javascript,Html,Dom,Setattribute,假设这段代码使用DOM()创建一个带有plainJavaScript的表: 使用向元素添加属性,如下所示: var td1 = document.createElement('td'); var td2 = document.createElement('td'); td1.setAttribute('class', 'className'); td2.setAttribute('class', 'className'); 希望这有帮助。使用向元素添加属性,如下所示: var td1 = d
var td1 = document.createElement('td');
var td2 = document.createElement('td');
td1.setAttribute('class', 'className');
td2.setAttribute('class', 'className');
希望这有帮助。使用向元素添加属性,如下所示:
var td1 = document.createElement('td');
var td2 = document.createElement('td');
td1.setAttribute('class', 'className');
td2.setAttribute('class', 'className');
希望这能有所帮助。请执行以下操作:
table.setAttribute("id", "myId");
阅读:
使用相同的函数设置类
,就像前面提到的@Zakaria一样。执行以下操作:
table.setAttribute("id", "myId");
阅读:
使用相同的函数设置
类
,就像前面提到的@Zakaria一样。不鼓励引用。结帐:)感谢@RahulDesai的介入。。(链接更新为https://developer.mozilla.org
)不鼓励引用。结帐:)感谢@RahulDesai的介入。。(链接更新为https://developer.mozilla.org
)如果您像我一样是引导程序迷,请添加with:table.setAttribute('class','table')
如果您像我一样是引导程序迷,请添加with:table.setAttribute('class','table')