在onclick函数中传递id [英] Pass id in onclick function
问题描述
我有这样的样子:
var array = [name1,imagesrc1,name2,imagesrc2,name3,imagesrc3,...];
我打印图像,但我想回想一下当我点击图像时某个地方写入名称(或者提醒名称)的功能。
我的代码是:
$ p $ 函数RightTable(objecto,wrappercontent)
{$ b $ (j = 0; j
var div = document.createElement('div');
var immagine = document.createElement('img' );
immagine.src =http://www.mysite.com/png/public/card/+ objecto [j + 1] +?width = 292;
immagine.setAttribute('class','card');
immagine.setAttribute('id',objecto [j]);
immagine.setAttribute('onClick',alertID(* idoftheimage * ));
div.appendChild(immagine);
wrappercontent.appendChild(div);
j + 1;如何传递给alertID(
$ p $) )图像的id是用户的名字?
I have like this: var array = ["name1","imagesrc1","name2",imagesrc2","name3","imagesrc3",...];
I print the images but I would like to recall a function that writes the name somewhere (or makes an alert with the name) when I click on the image.
My code is:
function RightTable(objecto,wrappercontent)
{
for(j=0;j<objecto.length;j++)
{
var div= document.createElement('div');
var immagine = document.createElement('img');
immagine.src= "http://www.mysite.com/png/public/card/" + objecto[j+1] + "?width=292";
immagine.setAttribute('class', 'card');
immagine.setAttribute('id' , objecto[j]);
immagine.setAttribute('onClick', "alertID(*idoftheimage*));
div.appendChild(immagine);
wrappercontent.appendChild(div);
j+1;
}
}
How can I pass to alertID() the id of the image that is the name of the user?
immagine.setAttribute('onClick', "alertID(this.id)");
这篇关于在onclick函数中传递id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!