setAttribute 和 getAttribute区别
² 赋值....setAttribute("a","1") 将1赋值给a
² 取值....getAttribute("a") 取出a的值,为1
在IE中是不认识class属性的,需改为className属性,同样,在Firefox中,也是不认识className属性的,Firefox只认识class属性,所以通常做法如下:
element.setAttribute(class, value); //for firefox
element.setAttribute(className, value); //for IE
IE:可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性
例如:设置 input 元素的 type 属性:
document.getElementsByTagName("input")[0].setAttribute("type","button");
Firefox:只能使用getAttribute()获取自定义属性.
解决方法:统一通过getAttribute()获取自定义属性
document.getElementById('box').getAttribute('id');//获取元素的 id 值
document.getElementById('box').id;//获取元素的 id 值
document.getElementById('box').getAttribute('mydiv');//获取元素的自定义属性值
document.getElementById('box').mydiv//获取元素的自定义属性值, IE 不支持非
document.getElementById('box').getAttribute('class');//获取元素的 class 值,IE 不支持
document.getElementById('box').getAttribute('className');//非 IE 不支持
PS:在 IE7 及更低版本的IE浏览器中,使用 setAttribute()方法设置 class 和 style 属性是没有效果的,虽然 IE8 解决了这个bug,但还是不建议使用。
removeAttribute()方法
removeAttribute()可以移除 HTML 属性。
document.getElementById('box').removeAttribute('style');
PS:IE6 及更低版本不支持 removeAttribute()方法。
setAttribute 和 getAttribute区别相关推荐
- JSP中getParameter和getAttribute区别
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...
- request.getParameter() 和request.getAttribute() 区别
request.getParameter() 和request.getAttribute() 区别 getParameter 是用来接受用post个get方法传递过来的参数的. getAttribut ...
- JSPServlet中request.getParameter() 和request.getAttribute() 区别
一.request.getParameter() 和request.getAttribute() 区别 (1)request.getParameter()取得是通过容器的实现来取得通过类似post,g ...
- 运用用setAttribute和getAttribute
用setAttribute和getAttribute设置和获取模拟登陆的界面 getParamete与getAttribute的用法 HttpServletRequest类既有getAttribute ...
- setAttribute、getAttribute 和 getParameter
一.setAttribute setAttribute这个方法的作用就是保存数据,然后还可以用getAttribute方法来取出,在JSP内置对象session和request中都有这个方法. set ...
- jsp中setAttribute与getAttribute方法使用介绍
jsp中setAttribute与getAttribute方法使用介绍,然后还可以用getAttribute方法来取出. setAttribute.jsp页面源码实例,设置保存当前的日期: <% ...
- request.getParameter() request.getAttribute()区别
一.当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数.例如a.jsp和b.jsp之间为链接关系, a.jsp中有以下代码: <form name= ...
- java中setattribute_jsp中setAttribute与getAttribute方法使用介绍
jsp中setAttribute与getAttribute方法使用介绍,然后还可以用getAttribute方法来取出. setAttribute.jsp页面源码实例,设置保存当前的日期: -//W3 ...
- setAttribute() 与 getAttribute() 用法剖析及选项卡操作的实例展示,这一篇就够了
Ⅰ.在 MDN 上 setAttribute() 与 getAttribute() 函数的用法解释(很详细): 1.Element.setAttribute(): 其一.摘要: 设置指定元素上的某个属 ...
最新文章
- 【c语言】整型数据的溢出
- 英国最新报告:40% AI公司其实没用任何AI技术
- Inno Setup使用教程大全
- 总说手机没有“好壁纸”,Python一次性抓取500张“美女”图片,够不够用!
- url存在宽字节跨站漏洞_利用WebSocket跨站劫持(CSWH)漏洞接管帐户
- 如何解决uchome自带编辑器无法获取uchome编辑器里面的值问题?(uchome二次开发)...
- TokenInsight:反映区块链行业整体表现的TI指数较昨日同期下跌5.04%
- Jupyter notebook 转 pdf [完整转换]
- scp实现mac与linux服务器之间文件传输
- OD点击寄存器变色OD
- 一文搞懂利用Flask-Babel实现网页多语言翻译切换
- SpringBoot+websocket 实现web聊天功能(单聊、保存消息)
- w10计算机右键管理,Win10右键菜单怎么管理
- 高中数学知识点:导数的概念及运算(复习+解析+答案)
- 网络、域名、DNS、A记录以及MX记录的基本概念
- jmeter-BeanShell预处理器与BeanShell后置处理器的使用
- 建数据库表需要注意哪些点
- [MIT]微积分重点学习笔记 目录
- 转个有意思的东西: 脑残体全论(2007-08-20 13:48)
- 西工大计算机夏令营面试
热门文章
- 内存泄露方式有哪些和如何查询内存泄露?
- 示波器探头x10、x1挡位
- php artisan migrate,关于laravel 5.1下php artisan migrate的使用
- 错误解决:hive报错Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
- Linux 中 Netcat 工具的使用
- SSL证书的根证书和中间根证书的区别
- 制作 Google Chrome 绿色版
- 从零开始搭建自己的网站可外网访问从购买服务器开始
- 1.HTTP网络编程
- Oracle对象——视图之简单视图与视图约束