当前位置:网站首页>nodetype中值1、2、3分别代表什么意思
nodetype中值1、2、3分别代表什么意思
2022-08-01 07:23:00 【前端切图仔Zz】
疑问:
viewer.js插件源码里面有这么一句(如上图),究竟是代表什么意思呢?
if (!element || element.nodeType !== 1) {
throw new Error('The first argument is required and must be an element.');
}
解析:
JavaScript中的所有节点类型都继承自Node类型,因此所有节点类型都共享相同的基本属性和方法。每个节点都有一个nodeType属性,用于表明节点的类型。
nodeType属性返回选定节点的节点类型,可以让我们知道、区分文档中的各个节点。
语法:
elementNode.nodeType
返回值:字符串值,代表节点的节点类型。
nodeType属性一共有12种取值(1~12),对应不同的节点。节点类型由在Node类型中定义的下列12个常量来表示,任何节点类型必居其一:
示例:
alert(Node.DOCUMENT_NODE); //9
alert(document.nodeType == Node.DOCUMENT_NODE); //true,在IE中无效
alert(document.nodeType == 9); //true,适用于所有浏览
边栏推荐
猜你喜欢
随机推荐
curl (7) Failed connect to localhost8080; Connection refused
LeetCode 415:字符串相加
GO错误处理方式
Compare two objects are the same depth
特别数的和
I have three degrees, and I have five faces. I was "confessed" by the interviewer, and I got an offer of 33*15.
Self-made a remote control software - VeryControl
配置我的kitty
从购买服务器到网站搭建成功保姆级教程~超详细
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的pad_fn函数与gt::fmt函数一起用于填充包含数值的特定列、对数据列的数值进行十进制对齐(从小数点对齐)
JSON 与 JS 对象的区别
我的创作纪念日
Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
my creative day
Srping中bean的生命周期
奇葩问题 npm install 报错 gyp ERR
C语言学习概览(二)
微信小程序请求封装
我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
Classwork (7) - #598. remainder operation (mod)