55 lines
1.5 KiB
HTML
55 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
<link rel="stylesheet" href="./index.css">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
list-style: none;
|
|
}
|
|
|
|
.main img {
|
|
height: 200px;
|
|
width: 300px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="main"></div>
|
|
</body>
|
|
<script src="./index.js"></script>
|
|
<script>
|
|
var img = [
|
|
`https://img0.baidu.com/it/u=1132032928,2577726940&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=1082`,
|
|
`https://img2.baidu.com/it/u=3395582942,4228440123&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500`,
|
|
`https://img2.baidu.com/it/u=4247972487,2176045580&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313`,
|
|
`https://img2.baidu.com/it/u=3081609058,4054949655&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=281`
|
|
];
|
|
|
|
//将图片显示到网页上的循环
|
|
img.forEach(v => { //function (v) {
|
|
$(".main").innerHTML += ` <img src="${v}" alt="">`
|
|
})
|
|
_(".main img").forEach((v, i) => {
|
|
v.onclick = () => {
|
|
console.log("被点击了:", v);
|
|
}
|
|
})
|
|
|
|
function $(className) {
|
|
return document.querySelector(className)
|
|
}
|
|
|
|
function _(className) {
|
|
return document.querySelectorAll(className)
|
|
}
|
|
</script>
|
|
|
|
</html> |