<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
function demo1(){
//获得id名称是inpl对象节点
var inpl = document.getElementById("inpl");
//获得节点对象的属性
var ty = inpl.type;
var va = inpl.value;
var na = inpl.name;
alert(ty+"---"+va+"----"+na);
//操作元素的属性 就是修改他的属性
inpl.type = "button";
inpl.value = "测试改变";
//获得元素的属性
var ty1 = inpl.getAttribute("type");
//获得属性的修改值
var va2 = inpl.getAttribute("value");
alert(va2s);
}
</script>
</head>
<body>
<input type="button" value = "点击" onclick="demo1()"/>
<input type="text" id ="inpl" value="张三" name ="unname"/>
</body>
</html>
22.5 JS DOM操作属性
最新推荐文章于 2022-10-21 13:33:39 发布