Internet Explorer 8不允许动态创建按钮

时间:2012-08-03 15:24:51

标签: javascript html css

当我尝试动态创建按钮时,Internet Explorer会显示错误。虽然它在firefox中运行良好

var deleteButton = document.createElement('input');
 ratingSliderContainer.appendChild(deleteButton);
 deleteButton.setAttribute('type','button');
 deleteButton.setAttribute('value','delete');

在第三行显示错误

1 个答案:

答案 0 :(得分:7)

一旦输入添加到DOM,您就无法修改输入的type。尝试重新排序你的陈述,如下:

var deleteButton = document.createElement('input');
deleteButton.setAttribute('type','button');
deleteButton.setAttribute('value','delete');
ratingSliderContainer.appendChild(deleteButton);