1、getAttribute()——获取属性的值
描述:获取节点属性的值。
语法:nodeObj.getAttribute(name)
参数:name代表当前节点的某个属性。
举例:var src = imgObj.getAttribute(“src”)
2、setAttribute()——添加属性
描述:给某个节点添加属性。
语法:nodeObj.setAttribute(name,value)
参数:
name代表属性名称。
value代表属性的值。
举例:imgObj.setAttribute(“src” , “images/02.jpg”)
3、removeAttribute()——删除属性
描述:删除某个节点的属性。
描述:获取节点属性的值。
语法:nodeObj.getAttribute(name)
参数:name代表当前节点的某个属性。
举例:var src = imgObj.getAttribute(“src”)
2、setAttribute()——添加属性
描述:给某个节点添加属性。
语法:nodeObj.setAttribute(name,value)
参数:
name代表属性名称。
value代表属性的值。
举例:imgObj.setAttribute(“src” , “images/02.jpg”)
3、removeAttribute()——删除属性
描述:删除某个节点的属性。
语法:nodeObj.removeAttribute(name)
<html>
<head>
<title>节点访问</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
</style>
<script type="text/javascript">
window.οnlοad= function(){
var imgObj = document.body.firstChild;
imgObj.setAttribute("src","001.jpeg");
imgObj.setAttribute("width","400px");
imgObj.setAttribute("border",2);
imgObj.setAttribute("style","padding:10px");
imgObj.setAttribute("onClick","remove(this)");
}
function remove(obj){
obj.removeAttribute("width");
obj.removeAttribute("src");
}
</script>
</head>
<body ><img src="">
</body>
</html>