我是 JS 新手,我需要帮助将随机生成的 ID 添加到当我们单击出现在 Canvas 上的图像上。这些出现在 Canvas 上的图像必须分配一个 ID。谁能给我建议?
在 HTML 上:
<FORM>
<INPUT type="button" value="+"onClick="Add(new IMGid)">
<input type="text" id="amount" value=0 maxlength="3" size="1" onKeyPress="return numeralsOnly(event)">
<INPUT type="button" value="-" onClick="Remove()">
</FORM>
在 Javascript 文件上:
function Add(new IMGid) {
newIMG = document.createElement("IMG");
newIMG.id = "IMG" + newIMGid;
newIMG = document.getElementById("divIMG1").appendChild(newIMG);
var uniqueNum = Math.floor(Math.random()*99999);
var newIMGid = newImg.attr('uniqueNum');
if (document.getElementById('amount').value < 100){
document.getElementById('amount').value++;
newIMG = document.createElement("IMG");
x = Math.random() * 200;
y = Math.random() * 160;
c5_context.drawImage(bluefish, x, y, 58, 100).value++;
//added by Luke
a = document.createElement("IMG").setID;
Element.attr('IMG', 'random');
//--------------------
document.getElementById("imagedest").appendChild(newIMG);
c5_context.drawImage(anchovies, x, y, 58, 100).value++;
document.write(newIMG);
}
}