我一直在研究这段代码,我想我必须要接近。我试图显示一个阵列中的图像,当时只有一个按钮引出一个阵列。此刻,所有照片同时显示,然后复制。你能告诉我我做错了什么吗?
<script>
var currentTrial = 0;
var trials;
var stimuli;
stimuli = new Array();
var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0].src = 'images/pie1a.png';
imgArray[1] = new Image();
imgArray[1].src = 'images/pie1b.png';
imgArray[2] = new Image();
imgArray[2].src = 'images/pie2a.png';
imgArray[3] = new Image();
imgArray[3].src = 'images/pie2b.png';
function NextTrial() {
$("#trial" + currentTrial).hide();
currentTrial++;
if (currentTrial < imgArray.length)
$("#trial" + currentTrial).delay(250).show();
else {
alert("experiment over");
}
trials = new Array();
for (var j = 0; j < imgArray.length; j++) {
var stimuli = '<div class="page">' + '<img src="' + imgArray[j].src + '"/>' + '</div>';
trials.push(stimuli);
}
for (var i = 0; i < trials.length; i++) {
$('.experiment').append('<div class="page" id="trial' + i + '">' + trials[i] + '</div>');
}
}
$(function() {
$("#pie").click(function() {
NextTrial();
});
});
</script>
网站代码:
<body>
<div class="experiment">
<p> hello world </p>
<button id="pie"> Show me the pie! </button>
</div>
</body>