JS中setAttribute的使用
来源:互联网 发布:js 获取数组长度 编辑:程序博客网 时间:2024/06/05 10:46
在web开发中,经常会为某个标签设置属性,那么就可以利用js的setAttribute()方法为标签的属性设置值。
下面的内容翻译自W3C DOM Level 1中关于setAttribute方法的说明.
具体的方法参数如下:
object.setAttribute(sName, vValue [, iFlags])
参数:
必填项. String类型,属性名
返回值
无返回值.
备注
如果指定的属性不存在,该方法讲为object添加新属性及值.
注意,当拼写属性名时. 如果 iFlags 设置成 1 并且 指定的sName 参数在该属性上没有相同名字时(包括大小写), object讲为之创建新属性.
如果object有两个或多个相同的属性名, 仅在值上不同时, iFlags设为 0, 该方法仅保存第一个被创建属性的值,其她的同名属性将被忽略.
使用该方法设置 CLASS 属性时, 请将sName 设为 "className",以符合Dynamic HTML (DHTML) 特性.(其实"className"仅适合在IE下使用,FF下要用"class")
firefox等可以使用
var dom=document.getElementById("name");
dom.setAttribute("style","width:10px;height:10px;border:solid 1px red;") ;
IE中则必须使用style.cssText
var dom=document.getElementById("name");
dom1.style.cssText = "width:10px;height:10px;border:solid 1px red;";
补充一下,目前style.cssText类似innerHTML了,已经成为一个web开发的事实标准。因此测试显示firefox浏览器也支持这种方式。
- JS中setAttribute的使用
- js的setAttribute的使用
- js中setAttribute 的兼容性
- js中setAttribute 的兼容性
- js中setAttribute 的兼容性
- javascript中setAttribute的使用
- getAttribute/setAttribute的使用
- Web开发中js的setAttribute方法参数说明
- js的setAttribute中class和className浏览器兼容问题
- IE中使用setAttribute方法设置属性的问题
- JavaScript DOM getElementByTagName 中关于 getAttribute() 和setAttribute()的使用
- 项目:对于Servlet中 request.setAttribute()的使用
- IE中setAttribute的疑惑
- js中setAttribute()和getAttribute()用法
- js 中getAttribute和setAttribute属性
- js-getAttribute与setAttribute的用法
- setAttribute使用
- js中设置样式的几种方式(setAttribute,className)
- ADO.NET的内置对象
- Ubuntu 版本升级
- Windows8 开发者预览版发布(微软官方原版)
- 如何减少编码过程中的错误
- runtime exception
- JS中setAttribute的使用
- android插拔耳麦广播android.intent.action.HEADSET_PLUG中间出的问题
- servlet3.0 资料收集
- 软件列表
- JDBC总结
- 你是否在开发正确的产品?
- 菜鸟带你秒杀单片机之51单片机篇—定时器
- Lucene.Net 实现groupby并可以加入自定义过滤功能
- 从程序上传数据到服务器文件中