Dom 节点的属性访问

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.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>



    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值