我创建了一个函数,它创建一个新的 img 并将其放入每个具有“绘制”css 类的标签中:
function putPiece(){
var painted = document.querySelectorAll('.painted');
for (var i = 0, len = painted.length; i < len; i++) {
var a = i+1
var squareID = painted[i].id;
painted[i].taken = 'BP'+a;
var img = document.createElement("img");
painted[i].appendChild(img);
img.id = "BP"+a; //unique ID for every img
img.src = "blackP.png"; //the image to use
img.pstn = squareID; //the ID of the <td> it's in
}
}
如上所述,我为每个对象赋予了属性。现在我想创建一个包含所有“img”对象的“img.pstn”的数组。有任何想法吗?提前谢谢!