简体   繁体   中英

random picture script for new app

I am creating an app through AppMaker and I want a random picture to appear when someone clicks the icon. I found a script online. I entered the script in (where they accept html on a screen) and it doesn't seem to run when I test it. I created several test pictures and uploaded them to my online site and then ran this script. Any help would be appreciated. The script is as follows:

<script type="text/javascript">
    var total_images = 2;
    var random_number = Math.floor((Math.random(2)*total_images));
    var random_img = new Array(3);
    random_img[0] = '<a href="http://mymoonspirit.com/images/Tarot1.jpg"><img src="images/Tarot1.jpg"></a>';;
    random_img[1] = '<a href="http://mymoonspirit.com/images/Tarot2.jpg"><img src="images/Tarot2.jpg"></a>';;
    document.write(random_img[random_number]);
</script>`

I've looked around and this looks like the best solution;

var image-number = Math.floor(Math.random() * random_img.length);
var image = random_img[image-number];

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