封装函数减少代码量

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="button" value="显示大图" id="btn" />
<img src="images/1.jpg" alt="" id="btn2">
<script>
function my$(id){
return document.getElementById(id);
}

// document.getElementById("btn").onclick=function() {
// document.getElementById("btn2").src = "images/2.jpg";
// };
my$("btn").onclick=function() {
my$("btn2").src = "images/2.jpg";
};
</script>
</body>
</html>
posted @ 2019-01-20 00:38  燕十三丶  阅读(173)  评论(0编辑  收藏  举报
AmazingCounters.com