问题
I don't think "simplest" is subjective.
Looking for a hostable photo gallery that does nothing but show an image and provide "next image" and "previous image" but all without reloading the page. Obviously precaching would be nice too. PHP, Python, Ruby, or JS.
回答1:
If you want simple, maybe something like this?
<html>
<body>
<div>
<img id="image">
</img>
</div>
<table>
<tr>
<td onclick="getImage("previous");">Previous</td>
<td onclick="getImage("next");">Next</td>
</tr>
</table>
<script type="text/javascript">
counter = 0;
nextImage = new Image();
previousImage = new Image();
getImage = function(what) {
if (what === "previous") {counter--;}
else {counter++;}
nextImage.src = "http://www.example.com/image?data=" + (counter + 1);
previousImage.src = "http://www.example.com/image?data=" + (counter - 1);
document.getElementById("image").src = "http://www.example.com/image?data=" + counter;
}
</script>
</body>
</html>
来源:https://stackoverflow.com/questions/5628108/simplest-ajax-photo-gallery