您的位置:首页 > 其它

20、DOm--操纵元素属性

2016-06-03 16:58 375 查看
1、操纵元素属性
 .元素属性操作

. 第一种: oDiv.style.display="bolck";
. 第二种: oDiv.style["diaplay"]="block";
. 第三种: Dom方式
 .Dom方式操作元素属性
   . 获取 getAttribute(属性名称)
   . 设置 setAttribute(属性名称,数值)

   . 删除 removeAttribute(属性名称)

1.1 html代码

<body>
<button type="button" id="oBtn">点击</button>
</body>
1.2 JavaScript代码

<script type="text/javascript">
window.onload = function() {
//1、获取标签元素属性的数值
var obtn = document.getElementById("oBtn");
obtn.onclick = function() {
var type = this.getAttribute("type");
alert(type);
}
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息