我想做的就是能够使用向上和向下箭头逐步浏览按顺序命名的图像。我错过了一些简单的东西,我可以使用一些帮助。up 和 down 字段不起作用。任何帮助表示赞赏。这是我的代码:
HTML:
<div id = "up" class= "5" idnum= "number5">up up up</div>
<img src="img/n5.png" id = "number5">
<div id = "down" lass= "5" idnum= "number5">down down down</div>
<div id = "up" class= "26" idnum= "number4">up up up</div>
<img src="img/n26.png" id = "number4">
<div id = "down" lass= "26" idnum= "number4">down down down</div>
<div id = "up" class= "28" idnum= "number3">up up up</div>
<img src="img/n28.png" id = "number3">
<div id = "down" lass= "28" idnum= "number3">down down down</div>
<div id = "up" class= "30" idnum= "number2">up up up</div>
<img src="img/n30.png" id = "number2">
<div id = "down" lass= "30" idnum= "number2">down down down</div>
<div id = "up" class= "35" idnum= "number1">up up up</div>
<img src="img/n35.png" id = "number1">
<div id = "down" lass= "35" idnum= "number1">down down down</div>
JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$("#up").click(function () {
var ball = $(this).attr("class");
var idnum = $(this).attr("idnum");
var test = $(this).find("img").attr("id");
ball++;
console.log("ball = "+ball);
console.log("idnum = "+idnum);
console.log("test = "+test);
$("#"+idnum).attr("src","img/n"+ball+".png");
});
$("#down").click(function () {
var ball = $(this).attr("class");
var idnum = $(this).attr("idnum");
var test = $(this).find("img").attr("id");
ball--;
console.log("ball = "+ball);
console.log("idnum = "+idnum);
console.log("test = "+test);
$("#"+idnum).attr("src","img/n"+ball+".png");
});
});
</script>
我知道我的代码在这一点上真的很笨重和臃肿,但这是多次错误测试的结果,没有让东西正常工作。