js实例教程-基于jQuery实现图片的前进与后退功能

发布时间:2018-11-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-基于jQuery实现图片的前进与后退功能脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

代码如下:

<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#myp{ position:absolute; width:500px; height:400px; top:50%; left:50%; margin-top:-200px; margin-left:-290px; }
img{ width:480px; height:380px;}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
VAR array = [1, 2, 3, 4, 5, 6];
var count = 0;
//后退
$('#Button1').click(function () {
if (count > 0) {
count--;
$('img').attr('src', 'images/' + array[count] + '.jpg');
}
})
//前进
$('#Button2').click(function () {
if (count < 5) {
count++;
$('img').attr('src', 'images/' + array[count] + '.jpg');
}
})
})
</script>
</head>
<body>
<p id=";myp">
<table><tr><td><input id="Button1" type="button" value="<" /></td><td><img src="images/1.jpg" /></td><td><input id="Button2" type="button" value=">" /></td></tr></table>
</p>
</body>
</html>

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#myp{ position:absolute; width:500px; height:400px; top:50%; left:50%; margin-top:-200px; margin-left:-290px; }
img{ width:480px; height:380px;}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var array = [1, 2, 3, 4, 5, 6];
var count = 0;
//后退
$('#Button1').click(function () {
if (count > 0) {
count--;
$('img').attr('src', 'images/' + array[count] + '.jpg');
}
})
//前进
$('#Button2').click(function () {
if (count < 5) {
count++;
$('img').attr('src', 'images/' + array[count] + '.jpg');
}
})
})
</script>
</head>
<body>
<p id="myp">
<table><tr><td><input id="Button1" type="button" value="<" /></td><td><img src="images/1.jpg" /></td><td><input id="Button2" type="button" value=">" /></td></tr></table>
</p>
</body>
</html>

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦!&nbsp;js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-基于jQuery实现图片的前进与后退功能全部内容,希望文章能够帮你解决js实例教程-基于jQuery实现图片的前进与后退功能所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。