我试图让此代码以一种方式工作,即我单击第一项它将执行一个功能,而当我单击第二项时它将执行不同的功能。现在他们都做同样的事情,我似乎无法把它分开。
var list = [];
list[0] = ["zero"];
list[1] = ["one"];
list[2] = ["two"];
list[3] = ["three"];
function Make(){
for ( var i = 0; i < 4 ; i++ ) {
var div = document.createElement("div");
div.style.width = "10px";
div.style.height = "10px";
div.style.background = "white";
div.style.color = "black";
div.style.top = "0px";
div.style.left = "0px";
div.style.margin = "10px 10px auto";
div.style.cursor = "pointer";
div.innerHTML = list[i];
!function(){
var index = 0;
div.onclick = function () { alert("this works"); };
}();
document.body.appendChild(div);
}
}