- 操作样式
- var a=document.getElementById("h")
- a.style.backgroundColor="red"
- alert(a.style.backgroundColor)
- a.style.width="" 属性值为空的时候就是删除了样式
- <div id="aaa">
- <span>hahaha</span>
- </div>
- </body>
- <script>
- //document整个文档
- //控制元素
- //var a=document.getElementById("aaa")
- /*a.remove()*/; //移除元素,移除只是在浏览器显示页面移除了。
- //var bb=document.createElement("span")
- //a.appendChild(bb) //追加子元素
- //操作元素
- //var a=document.getElementById("aaa");
- /*alert(a.innerText) */ //innerText 取元素中的文本内容
- a.innerText="world" //给元素赋文本值
- //alert(a.innerhtml) //区元素的HTML代码内容
- //a.innerHTML="" //给元素放一个HTML代码
- 表单元素
- /*var a=document.getElementById()
- a.value="yonghuming";//给元素赋值
- alert(a.value);*///取值
- 操作属性
- var a=document.getElementById("aaa");
- a.setAttribute("bs","100") ////给标签加属性、属性
- a.getAttribute("bs") //获取属性值
- a.removeAttribute("bs") // 移除属性
- /*var a=document.getElementById("aaa");
- a.setAttribute("bs","200");*/
- //alert(a.getAttribute("bs"));
来源: http://www.cnblogs.com/gaofangquan/p/7050662.html