<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>常用元素的属性操作</title>
</head>
<body>
<button id = 'idh'>刘德华</button>
<button id = 'zxy'>张学友</button> <br>
<img src="图片路径" alt="" title = '刘德华'>
<script>
//1.获取元素
var ldh = document.getElementById('ldh');
var zxy = document.detElementById('zxy');
var img = document.querySelector('img');
//2.注册事件 处理程序
//通过修改src,title属性,
zxy.onclick = function(){
img.src = '图片路径';
img.title = '张学友';
}
ldh.onclick = function(){
img.src = '图片路径';
img.title = '刘德华';
}
</script>
</body>
</html>
webapis_09_常用元素的属性操作
最新推荐文章于 2024-11-08 16:09:18 发布