We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
页面标签的data-*会映射到对应的DOM元素的dataset属性上。
data-*
页面标签需要全部小写,可以使用连字符-连接每个单词; dataset上的属性需要转化为驼峰格式。
-
比如:
<div id="test" data-my-data="hello"></div> document.querySelector('#test').dataset.myData === "hello" // true
attribute翻译成中文术语为“特性”,property翻译成中文术语为“属性”。
我们在HTML文档里给元素附加的特性:
<div hello="world"></div> 该div元素的attributes就会有hello
attributes是通过setAttribute()和removeAttribute()来维护的。
setAttribute()
removeAttribute()
property指的是HTML元素对应的DOM对象的键值对属性。
property包含attributes。
JS 引擎和渲染引擎(浏览器内核)是独立实现的。当我们用 JS 去操作 DOM 时,本质上是 JS 引擎和渲染引擎之间进行了“跨界交流”。这个“跨界交流”的实现并不简单,它依赖了桥接接口作为“桥梁”。
方案:
HTMLElement.dataset attribute和property的区别
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1. 获取元素样式
2. dataset
页面标签的
data-*
会映射到对应的DOM元素的dataset属性上。页面标签需要全部小写,可以使用连字符
-
连接每个单词;dataset上的属性需要转化为驼峰格式。
比如:
3. attribute 和 property
attribute翻译成中文术语为“特性”,property翻译成中文术语为“属性”。
attribute
我们在HTML文档里给元素附加的特性:
attributes是通过
setAttribute()
和removeAttribute()
来维护的。property
property指的是HTML元素对应的DOM对象的键值对属性。
property包含attributes。
4. DOM优化原理和方案
JS 引擎和渲染引擎(浏览器内核)是独立实现的。当我们用 JS 去操作 DOM 时,本质上是 JS 引擎和渲染引擎之间进行了“跨界交流”。这个“跨界交流”的实现并不简单,它依赖了桥接接口作为“桥梁”。
方案:
参考
HTMLElement.dataset
attribute和property的区别
The text was updated successfully, but these errors were encountered: