2

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

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

它在第三行显示错误

4

1 回答 1

7

type将输入添加到 DOM 后,您将无法修改它。尝试重新排序您的语句,如下所示:

var deleteButton = document.createElement('input');
deleteButton.setAttribute('type','button');
deleteButton.setAttribute('value','delete');
ratingSliderContainer.appendChild(deleteButton);
于 2012-08-03T15:26:50.460 回答