Home >Web Front-end >JS Tutorial >View pictures (forward and backward) function to implement js code_javascript skills

View pictures (forward and backward) function to implement js code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:35:27910browse

Note: The naming of pictures in the images folder is from 1 to 5.jpg.
Declared var array = [1, 2, 3, 4, 5]; This array stores the name of the picture.

Copy code The code is as follows:


< ;/title> <br><script src="Jquery1.7.js" type="text/javascript"></script> <br><style type="text/css"> <br>img <br>{ <br>width: 200px; <br>height: 200px; <br>} <br></style> <br><script type="text/javascript"> <br> $(function () { <br>var array = [1, 2, 3, 4, 5]; <br>var count = 0; <br>$('#Button1').click(function () { <br>if (count > 0) { <br>count--; <br>$('img').attr('src','images/' array[count] '.jpg'); <br> } <br>}) <br>$('#Button2').click(function () { <br>if (count <4) { <br>count ; <br>$('img').attr ('src', 'images/' array[count] '.jpg'); <br>} <br>}) <br>}) <br></script> <br></head> <br><body> <br><table> <br><tr> <br><td> <br><input id="Button1" type="button" value="<" / > <br></td> <br><td> <br><img src="images/1.jpg" /> <br></td> <br><td> <br><input id="Button2" type="button" value=">" /> <br></td> <br></tr> <br></table> <br></body> <br> </div> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="82291" class="copybut" id="copybut82291" onclick="doCopy('code82291')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code82291"> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br> <html xmlns="http://www.w3.org/1999/xhtml"> <br><head> <br><title>






















Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn