.tagName 和 .nodeName 的区别 [英] Difference between .tagName and .nodeName

查看:21
本文介绍了.tagName 和 .nodeName 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('this')[0].nodeName$('this')[0].tagName 有什么区别?

推荐答案

tagName 属性 专门用于元素节点(类型1节点)获取元素的类型.

The tagName property is meant specifically for element nodes (type 1 nodes) to get the type of element.

还有几种其他类型的节点(评论、属性、文本等).).要获取任何各种节点类型的名称,您可以使用 nodeName 属性.

There are several other types of nodes as well (comment, attribute, text, etc.). To get the name of any of the various node types, you can use the nodeName property.

当对元素节点使用nodeName时,你会得到它的标签名称,所以两者都可以真正使用,尽管你会得到使用 nodeName 时浏览器之间的一致性更好.

When using nodeName against an element node, you'll get its tag name, so either could really be used, though you'll get better consistency between browsers when using nodeName.

这篇关于.tagName 和 .nodeName 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆