当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 基于jQuery实现图片的前进与后退功能

基于jQuery实现图片的前进与后退功能

2018年10月30日  | 移动技术网IT编程  | 我要评论
代码如下: <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "https://www

代码如下:

<!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>

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网