简体   繁体   中英

PhoneGap - Can't Find variable

So I made a simple slideshow in js to display a photogalery in a page, the problem is that whenever I try the slideshow the console shows me the error

ReferenceError: Can't find variable: next

This is my code:

slideshow js code:

    <script>
var myImage= new Array(); 
myImage[0]="1.jpg";       
myImage[1]="2.jpg";
myImage[2]="3.jpg";
myImage[3]="4.jpg";
myImage[4]="5.jpg";
myImage[5]="6.jpg"; 
myImage[6]="7.jpg"; 
myImage[7]="8.jpg"; 
myImage[8]="9.jpg"; 
myImage[9]="10.jpg"; 
myImage[10]="11.jpg"; 
myImage[11]="12.jpg";   

var ImageCnt = 0;

function next(){
    ImageCnt++;
    document.getElementById("whiteBox").style.background = 'url(' + myImage[ImageCnt] + ')';
  }
function previous(){
    ImageCnt--;
    document.getElementById("whiteBox").style.background = 'url(' + myImage[ImageCnt] + ')';
  }
</script>

html body code:

<div data-role="content">
    <div id="whiteBox"></div>
    <a href="#" onclick="next();return false;"><img src="next.png"/></a>
    <a href="#" onclick="previous();return false;"><</a>
    </div>

I searched on the internet and found many similiar situations, but I could not find the solution.

Have you attemped to try call it in console?

Use Google chrome press CTRL+SHIFT+J and type in next();

Or try this;

<a href="#" onclick="javascript:next();"><img src="next.png"/></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM