js控制div及网页相关属性的代码
作者:bea
动态创建DIV:var div = document.createElement("div");
设置div属性及样式等:
div.title="this is a new div.";
div.class = "newDivClass";
div.innerHTML = "Test create a div element!";
div.style.styleFloat="left";
div.style.overflow="hidden";
div.style.marginLeft="8px";
div.style.marginTop="10px";
div.style.width="320px";
div.style.height="250px";
div.style.backgroundRepeat="no-repeat";
div.style.backgroundImage="url(image/bgred.jpg)"
将DIV添加到body:document.body.appendChild(div );
设置Attribute属性:
添加,设置:
(1). div.setAttribute("ok","ok?");
html: <div id="id" style="background-color: red;" ok="ok?"/>
(2). var ok = document.createAttribute("name");
div.setAttributeNode(ok);
html: <div id="id" style="background-color: red;" name=""/>
获取:
(1).div.getAttribute("ok");//ok?
(2)var v = div.getAttributeNode("ok").value;// div.getAttributeNode("ok")获取的是//AttributeNode对象。
删除
(1).document.getElementById("id").removeAttribute("ok");//ok为属性名。
(2).document.getElementById("id").removeAttributeNode(ok);//ok为AttributeNode对象。
很重要的一个方法
document.getElementsByTagName
猜你喜欢
您可能感兴趣的文章:
- JavaScript 未知高度元素垂直居中实现代码
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- Div+Js实现的带阴影菜单 微软以前网站曾用过
- Js倒计时代码,当鼠标离开页面与回到页面会自动停止与开始
- javascript强制弹出新窗口实现代码
- javaScript 删除确认实现方法小结
- jquery 表单取值常用代码
- JavaScript是否可实现多线程 深入理解JavaScript定时机制
- JavaScript 图片预览效果 推荐
- javascript 年月日联动实现核心代码
- 兼容firefox的文本框只能输入两位小数的数字的代码
- js Firefox 加入收藏夹功能代码 兼容Firefox 和 IE
- Javascript和Ajax中文乱码吐血版解决方案
- 利用jQuery的$.event.fix函数统一浏览器event事件处理
- jQuery 连续列表实现代码
- jQuery解决iframe高度自适应代码
- IE 上下滚动展示模仿Marquee机制
- Js获取table当前tr行的值的代码
- javascript 翻页测试页(动态创建标签并自动翻页)