JavaScript实现简单的图片切换【静态点击切换】


<html>
	<head>
		<meta charset="UTF-8">
		<title>图片切换title>
		<script type="text/javascript">
		/*调用函数方法*/
			/*定义数组来保存要切换的图片*/
			var imgs = ["img/bird.jpg","img/h5.jpg","img/a.jpg"];
			/*设置变量控制图片循环*/
			var count = 0;
			var changeimg = function(){
      
				var img = document.getElementById("img");
				img.src=imgs[count++];
				if(count==3) count=0;
			}
		script>
	head>
	<body>
		<img src="img/a.jpg" id="img" width="200px" height="200px" onclick="changeimg()"/>
		
			document.getElementById("img").οnclick=function(){
				this.src=imgs[count++];
				if(count==3){
					count=0;
				}
			}
		script>
		-->
	body>
html>

你可能感兴趣的:(前端笔记,网页图片切换,JavaScript)