<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>setAttribute设置属性</title>
<!--
setAttribute方法允许我们用属性节点的值做修改。
与getAttribute一样,setAttribute也只能用于元素节点。
setAttribute()方法需要我们向它传递两个参数:obiect.setAttribute(attribute,value)
-->
<script>
window.function(){
//把title属性的值改成like
document.getElementById("divHobby").setAttribute("title","like");
var title=document.getElementById("divHobby").getAttribute("title");
alert(title);
}
</script>
</head>
<body>
<div id="divHobby" title="hobby">
<ul>
<li>游泳</li>
<li>上网</li>
<li>拳击</li>
<li>音乐</li>
</ul>
</div>
</body>
</html>
Dom setAttribute获取元素节点内容
猜你喜欢
转载自blog.csdn.net/NaXieNianWoMenYiQ/article/details/86668912
今日推荐
周排行