不能更改< button>的“类型”用Javascript
问题描述:
在Chromium 7.0.517.44(64615)Ubuntu 10.10上,我似乎无法更改< button> 类型
/ code>元素:
On Chromium 7.0.517.44 (64615) Ubuntu 10.10, I seem to be unable to change the type
attribute of a <button>
element:
> blah = document.createElement("button")
<button></button>
> blah.type
"submit"
> blah.type = "button"
"button"
> blah.type
"submit"
帮助?
在Firefox 3.6.12和Opera 10.63上,可以正常工作:
On Firefox 3.6.12 and Opera 10.63, it works fine:
>>> blah = document.createElement("button")
<button>
>>> blah.type
"submit"
>>> blah.type = "button"
"button"
>>> blah.type
"button"
答
使用 setAttribute
。
blah.setAttribute('type', 'button');