首页 > 设计 > WEB开发 > 正文

js如何获取给定属性的属性值

2019-11-04 08:04:22
字体:
来源:转载
供稿:网友

js如何获取给定属性的属性值

js如何获取给定属性的属性值:在一些实际应用中需要取得给定属性的属性值,下面就简单介绍一下如何实现次效果。代码实例如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/CSS">.bottom{  width:100px;  height:100px;  background-color:green;}</style><script type="text/javascript">window.onload=function(){  alert(document.getElementsByTagName("div")[0].getAttribute("class"));}</script></head><body>  <div class="bottom"></div></body></html>

以上代码可以获取div的class属性的属性值。上面的代码中使用了getAttribute()函数,此函数的参数是一个字符串,用来规定要获取值的属性名称。

原文地址是:http://www.51texiao.cn/Javascriptjiaocheng/2015/0427/228.html


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表