为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这样写 用getAttribute()得不到nodeName属性?var arr=document.getElementsByTagName("li"); document.write(arr[0].getAttribute(nodeName));

为什么这样写 用getAttribute()得不到nodeName属性?var arr=document.getElementsByTagName("li");     document.write(arr[0].getAttribute(nodeName));

正在回答

1 回答

1,getAttribute()是用来获取属性值的,nodeName是标签名,不是属性,

2、标签的属性常见的有id,name,type等,

3、自定义属性也是可以的,比如<p abc="123"><p>里面的abc就是自定义的属性

4、getAttribute("abc")可以得到属性值123,但是不能这样写getAttribute(abc),

但是可以这样,abc="abc";getAttribute(abc);因为不加引号代表的是变量

2 回复 有任何疑惑可以回复我~
#1

码头菌 提问者

非常感谢!
2016-03-26 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么这样写 用getAttribute()得不到nodeName属性?var arr=document.getElementsByTagName("li"); document.write(arr[0].getAttribute(nodeName));

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号