【发布时间】:2010-07-26 13:27:00
【问题描述】:
似乎有时 object.setAttribute(attrib,value) 不等同于 javascript 中的 object.attrib=value?
我有以下代码,可以正常工作:
var lastMonthBn = document.createElement('input');
lastMonthBn.value='<'; // This works fine
lastMonthBn.type='button'; // This works fine
但下面的代码没有:
var div = document.createElement('div');
div.class = 'datepickerdropdown'; // No luck here!
所以我需要使用以下内容:
div.setAttribute('class','datepickerdropdown');
我的问题是,为什么?通过阅读this,我认为 object.setAttribute(blah,value) 与 object.blah=value 相同??
【问题讨论】:
标签: javascript dom