HTML中Attribute和JavaScript中property区别
来源:互联网 发布:mac系统无guid分区重装 编辑:程序博客网 时间:2024/04/25 06:18
Attribute是HTML标签中定义的属性
<div id="div" class="class" lang="ds" dir="ltr" title="title" userDefi="userDefi"></div>
例如上面定义的id,class,lang,dir,title,userDefi
都是Attribute
,都可以通过ele.getAttribute('id')
这样获取其值。
Property是JavaScript为元素对象定义的属性
var ele = document.getElementById('div'); ele.anotherProp = 'anotherP';
例如上面为ele
定义的anotherProp
.
共同拥有的属性
虽然Attribute
和Property
定义的属性分别在不同层面上,但是有以下几个属性是共享的:
id
class
lang
dir
title
<div id="div" class="class" lang="ds" dir="ltr" title="title" userDefi="userDefi"></div> var ele = document.getElementById('div'); ele.anotherProp = 'anotherP'; ele.id = 'anotherId'; console.log(ele.getAttribute('id'));//div console.log(ele.getAttribute('class'));//class console.log(ele.getAttribute('lang'));//ds console.log(ele.getAttribute('dir'));//ltr console.log(ele.getAttribute('title'));//title console.log('==============') console.log(ele.id);//div console.log(ele.className);//class console.log(ele.lang);//ds console.log(ele.dir);//ltr console.log(ele.title);//title console.log('==============') console.log(ele.anotherProp);//anotherP console.log(ele.getAttribute('anotherProp'));//null console.log(ele.getAttribute('userDefi'));//userDefi console.log(ele.userDefi);//undefined ele.id = 'anotherId'; 页面HTML标签同步显示id为anotherId
在页面改变input
框的输入值并不会影响input
的value
值
<input type="text" value="start" id="input"><input type="button" value="changevalue" id="btn"> btn.onclick = function () { input.value = 123; console.log(input.value);/123 console.log(input.getAttribute('value'));//start };
阅读全文
0 0
- HTML中Attribute和JavaScript中property区别
- JavaScript 中 Property 和 Attribute 的区别详解
- JavaScript 中 Property 和 Attribute 的区别详解
- javascript中attribute和property的区别详解
- javascript中attribute和property的区别详解
- JavaScript 中 Property 和 Attribute 的区别详解
- JavaScript 中 Property 和 Attribute 的区别详解
- C#中Attribute和Property的区别
- C#中attribute和property的区别
- dom中attribute和property的区别
- JS中Attribute 和 property的区别
- JS中Attribute 和 property的区别
- HTML中的attribute和property的区别
- HTML中的attribute和property的区别
- 高级编程语言中Property和attribute的区别
- 【转帖】C#中Property和Attribute的区别
- DOM中Property与Attribute的区别
- attribute和property区别
- 邝斌的ACM模板(Manacher 最长回文子串)
- APIO2010 特别行动队
- 移动端开发全屏遮罩层的简单制作
- [Git]Git的撤消操作-重置,签出和撤消
- html学习
- HTML中Attribute和JavaScript中property区别
- 使用mysql自带工具mysqldump进行全库备份以及source命令恢复数据库
- VIewPager+XListView+RadioButton实现布局
- HDU6103-Kirinriki
- 如何简单方便的用字体代替页面中常见常用的小图标小按钮(上)
- Android的线程
- 【随笔】Android Hybrid App 体系结构
- HDC, CDC, CClientDC, CWindowDC
- Linux C学习--getline()函数