您的位置:首页 > Web前端 > JavaScript

Javascript 点击切换图片(小demo)

2012-09-11 16:03 260 查看
简述:

为了掩饰几张网页, 用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'; //动态设定src
console.log(id);
}

</script>
<img id="image" width=1250 height=900 onclick='next()' src='./img/1.jpg' />
</body>
</html>


文件目录:



img

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: