4.10 随机展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="20">
<link rel="stylesheet" href="myCSS.css">
<script>
var index = 0;
function randomChange() {
var images = ["src/test_on.png","src/test_off.png"];
var myImage = document.getElementById("myImageID");
myImage.src = images[Math.abs(index % 2)];
index = Math.floor(Math.random() * 100) % 2;
}
function linkChange() {
document.getElementById("myImageID").parentNode.onclick = function () {
var links = ["https://www.baidu.com","https:www.google.com"];
document.location.href = links[index];
return false;
};
}
window.onload = linkChange;
</script>
</head>
<body>
<a href="https://www.baidu.com"><img id="myImageID" src="src/test_on.png"></a>
<button onclick="randomChange()">随机</button>
</body>
</html>