getAttrbute()方法
来源:互联网 发布:中国erp软件排行 编辑:程序博客网 时间:2024/05/16 12:12
getAttrbute()方法
通过元素节点的属性名称获取属性值
elementNode.getAttribute(name)
说明:
1.elementNode:使用getElementById(),getElementsByTagName()等方法,获取到的元素节点
2.name:要想查询的元素节点的属性名字
例子:使用getAttribute()方法,获取LI标签的title值。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>getAttribute()</title>
</head>
<body>
<p id="intro">课程列表</p>
<ul>
<li title="第1个li">HTML</li>
<li>CSS</li>
<li title="第3个li">JavaScript</li>
<li title="第4个li">Jquery</li>
<li>Html5</li>
</ul>
<p>以下为获取的不为空的li标签title值:</p>
<script type="text/javascript">
var con=document.getElementsByTagName("li");
for (var i=0; i< con.length;i++){
var text=con[i].getAttribute("title");
if(text!=null)
{
document.write(text+"<br>");
}
}
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>getAttribute()</title>
</head>
<body>
<h1 id="alink" title="getAttribute()获取标签的数值" onclick="hattr()">点击我,获取标签值</h1>
<script type="text/javascript">
function hattr(){
var anode=document.getElementById("alink");
var attr1=anode.getAttribute("id");
var attr2=anode.getAttribute("title");
document.write("h1变迁的ID:"+attr1+"<br>");
document.write("h1标签的title:"+attr2);
}
</script>
</body>
</html>
- getAttrbute()方法
- python中getattrbute问题
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- NGINX 进程通信机制
- IOS开发中的几种设计模式介绍
- is not used in any concrete target
- oracle中delete数据之后,如何恢复
- ubuntu下root用户与普通用户之前的切换命令
- getAttrbute()方法
- 三十岁的彷徨
- VS工程目录设置相关问题详解
- android平台Camera采集数据ffmpeg进行编码探究
- 配置laravel框架
- linux API---timerfd的使用方法
- 利用CURL定时重启无线路由器
- Struts2_13_默认的action
- Struts2的Action控制类的实现及Action访问Servlet API