标签:
一.找元素
①getElementById()根据ID找。
②getElementsByClassName()根据class找,返回数组。
③getElementsByTagName()根据标签名找,返回数组。
二.操作内容
1.普通元素。包括①innerText获取内容文本。②innerHTML获取内容代码。
2.表单元素。value
var a = document.getElementById("txt");
alert(a.value);
a.value = "ok";
三.操作属性
①setAttribute(属性名,属性值)设置属性
a.setAttribute("checked","checked");
②removeAttribute(属性名)移除属性
a.removeAttribute("checked");
③getAttribute(属性名)获取属性
alert(a.getAttribute("test"));
四.操作样式
a.style.width获取样式
操作样式
var a = document.getElementById("d");
1.获取样式,只能获取内嵌的
alert(a.style.width);
2.设置样式
a.style.fontSize = "30px";
3.修改样式
a.style.backgroundColor = "green";
a.style.color="white";
标签:
原文地址:http://www.cnblogs.com/zxl89/p/5898615.html