Javascript 点击切换图片(小demo)

来源:互联网 发布:os x 软件推荐 程序员 编辑:程序博客网 时间:2024/04/30 05:21

简述:

为了掩饰几张网页, 用JS就写了个简易的图片切换

里面有六章(可自定义张数)静态的图片,可以点击后循环切换


代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><body><script type="text/javascript">var id = 1;function next(){id = (id + 1) % 7;document.getElementById("image").src = './img/' + id + '.jpg'; //动态设定srcconsole.log(id);}</script><img id="image" width=1250 height=900 onclick='next()' src='./img/1.jpg' /></body></html> 

文件目录:

img


原创粉丝点击