菜鸟一枚,我给每个input绑定onclick时间,为什么图片和文字的数组显示不出来呢
<div class="wrap" id="wrap"><img id="img"src="one.jpg">
<input type="button" class="one"value="one">
<input type="button" class="two"value="two">
<input type="button" class="three"value="three">
<input type="button" class="fouth"value="fouth">
<span id="span"></span>
</div>
<script type="text/javascript">
var img = document.getElementById("img");
var wrap = document.getElementById("wrap");
var span = document.getElementById("span");
var one_btn = document.getElementById("one");
var two_btn = document.getElementById("two");
var three_btn = document.getElementById("three");
var fouth_btn = document.getElementById("fouth");
var pic = ["two.jpg","three.jpg","four.jpg","one.jpg"];
var text = ["1","2","3","4"];
var sumintputs = document.getElementsByTagName("input");
for (var i = 0; i < sumintputs.length; i++) {
sumintputs[i].onclick = function (){
this.style.width ="70px";
this.style.background ="pink";
img.src = pic[i];
span.innerHTML = text[i];
}
};
更多 0