When making web pages, you need to use JS to display images with special effects. The following is a simple image switching using JS.
Copy the code code as follows:
<html>
<head>
<script type="JavaScript">
var srr = new Array('Picture 1', 'Picture 2', 'Picture 3', 'Picture 4'); //Use the built-in array in JS to store data
vars = 0;
function chage() {
var img = document.getElementById('img1');
if (s <srr.length-1) {
s++;
}
else {
s = 0;
}
img.setAttribute('src', srr[s]);
}
function diaoyong() {
setInterval(chage, 1000);
}
</script>
</head>
<body onLoad="diaoyong();">
</body>
</html>