急,javascript属性节点问题?

来源:百度知道 编辑:UC知道 时间:2024/09/21 23:35:41
我要知道type怎么才能弹出2?

<input type=button value=wwww id=a onclick=alert(document.getElementById('a').type.nodeType)>

我getElementById('a').type.nodeType我写了type属性节点的节点类型了,为什么没弹出2啊?

弹出的是undefined啊?

<input type=button value=wwww id=a onclick=alert(document.getElementById('a').type.nodeType)>
你到底是要type还是要nodeType啊?
要type就这样写:document.getElementById('a').type
要nodeType就这样子写:document.getElementById('a').nodeType

getElementById('a').getAttribute('type').nodeType
除了id,class,style属性里的可以上面这样写,其他的最好用getAttribute和setAttribute,这样你的代码才能在所有xml文件里兼容。