我正在编写代码,以便人们可以单击图像,然后可以将单击的坐标记录在下表中。每当我更改某些内容时,图片都会出现并正常工作,或者表格会出现。我无法弄清楚出了什么问题。
这是代码:
var ready1 = prompt("Are you ready? Type yes or no.");
if (ready1 === "yes") {
var images = [
["http://i.imgur.com/UygMnuU.jpg"],
["http://i.imgur.com/eq3ruIo.jpg"],
["http://i.imgur.com/6JEleqR.jpg"]
];
var focuspoint = [];
var xcoordinates = [];
var ycoordinates = [];
var coords = [];
i = 0;
slide = $("#slide");
// var visualStatic = function () {
// setTimeout(function () {
// static.show();
//}, 5000);
// slide.attr("src", images[i++]);
//};
slide.click(function () {
if (i < (images.length + i)) {
slide.attr("src", images[i++]);
xcoordinates.push(e.pageX);
ycoordinates.push(e.pageY);
}
}).trigger("click");
}
var cols = ["X Coords", "Y Coords"];
table = document.createElement("table"),
row = document.createElement("tr"),
// populate the coords array
coords.push(xcoordinates);
coords.push(ycoordinates);
// setup for the heading row by looping through columns
for (var c = 0; c < cols.length; c++) {
td = document.createElement("td");
td.innerHTML = cols[c];
row.appendChild(td);
}
table.appendChild(row);
// now the columns are populated
for (var i = 0; i < coords[0].length; i++) {
row = document.createElement("tr");
for (var j = 0; j < coords.length; j++) {
td = document.createElement("td");
td.innerHTML = coords[j][i];
row.appendChild(td);
}
table.appendChild(row);
}
document.body.appendChild(table);