这段JS代码中,为什么获取不了标签的属性? javascriptnodeTypenodeValuenodeName 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你写错了,应该是x=document.getElementById("abc").nodeType; var x = document.getElementById("abc")[0].getAttributeNode("id").nodeType;alert(x); 就是说,标签的属性,不能用.属性名的方式来操作?一定要通过getAtrtribute,或setAttribute方法来操作,是这样子理解吗?还有,你那个“[0]”,是什么意思? <p id=abc></p><script>var x = document.getElementById("abc");alert(x.id);var o = x.getAttributeNode("id");alert(o.nodeType +':'+o.nodeName+':'+o.nodeValue);</script> document.getElementById("abc").getAttributeNode("id").nodeName 据我所知,用属性名操作获得的是属性名,不是节点,也就没有nodeType这样的属性节点类型了。[0]是说去取第一个节点,但是如果用getElementById的话,正常来说只有一个节点,不像使用getElementsByTagName,所以可以去掉。 如何实现隐藏div同时去掉input属性? jquery 读取xml问题 js中实现List存储 怎样得到childNodes的自己,比如id包含"class"字符的,可以用正则么? 如何用JS实现,在模式弹出窗体中输入值传回当前页 PHP中如何引进javascript中的内容 按一次"回车"相当于按两次"回车" 又是表单验证的问题 jsp不跳转,怎么实现给另一个jsp传值 怎么给li自动生成递增序号,大于9的时候,序号为10,而不为010? 请教一个checkbox连续选择的问题 不支持cookie属性或方法
x=document.getElementById("abc").nodeType;
var x = document.getElementById("abc")[0].getAttributeNode("id").nodeType;
alert(x);
<script>
var x = document.getElementById("abc");
alert(x.id);
var o = x.getAttributeNode("id");
alert(o.nodeType +':'+o.nodeName+':'+o.nodeValue);
</script>
[0]是说去取第一个节点,但是如果用getElementById的话,正常来说只有一个节点,不像使用getElementsByTagName,所以可以去掉。