PHP 文件代码:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<?php $transportation = array('foot', 'bike', 'car', 'plane'); ?>
<h2>Foot, Bike, Car, Plane</h2>
<p>
<input type="button" class="cycle" id="next" value="Next">
</p>
<h2 id="result">Current: plane</h2>
<p>
<input type="button" class="cycle" id="prev" value="Previous">
</p>
<script type="text/javascript">
var myarray = <?php echo json_encode($transportation); ?>;
$(document).ready(function () {
var current = -1;
$(".cycle").click(function () {
var darray = myarray;
if ($(this).attr("id") == "next") {
next(darray);
} else {
prev(darray);
}
});
function next(data) {
if (current != 3) {
$("#result").text("Current: " + data[++current]);
}
}
function prev(data) {
if (current != 0) {
$("#result").text("Current: " + data[--current]);
}
}
});
</script>
</body>
</html>
现场示例:
http://69.195.223.90/56454-11/