我通过多个线程阅读而未找到明确的答案。 我正在使用JavaScript库(Drinks.js)将多个小部件放在我的网页上。 下面的代码将一个单一的项目添加到我的div元素pnlThermo
:多个appendChild调用不起作用
function create(item) {
var thermo = Drinks.createElement('display');
thermo.setAttribute('id', item);
thermo.setAttribute('label', item);
Drinks.appendChild('pnlThermo', thermo);
}
好了,现在我想几个项目添加到同一个div元素。无论我使用for循环还是显式调用该函数,都只会渲染第一个项目。例如:
create('T1');
create('T2');
create('T3');
导致仅显示T1
。我可能错过了一些东西,我对JavaScript编程颇为陌生。
谢谢先进。
我在这里错过了什么吗? HTML元素“”是否存在? –
andlrc
我想你每次都使用相同的ID? –
@GurpreetSingh不会导致ID为'T1,T2,T3' – andlrc