Simplified JavaScript?

2015-08-16 9:50 am
var image = document.getElementsByClassName("image");

image[0].onmouseover = function() {slide(0)};
image[1].onmouseover = function() {slide(1)};
image[2].onmouseover = function() {slide(2)};
image[3].onmouseover = function() {slide(3)};
image[4].onmouseover = function() {slide(4)};
image[5].onmouseover = function() {slide(5)};
image[6].onmouseover = function() {slide(6)};
image[7].onmouseover = function() {slide(7)};

function slider(i) {...}

回答 (1)

2015-08-16 11:11 pm
for (var i = 0; i < 8; i++) image[i].onmouseover = function() { slide(i); };


收錄日期: 2021-04-23 23:09:47
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150816015013AAzVwWG

檢視 Wayback Machine 備份