当我单击它时,我想使用 img 标签的 innerhtml 更改图像我的代码如下所示
tempData +='<td >';
tempData +='<img src="'+frontImg+'" id='+ii+' onClick="flipImage(this.id);" />';//from where flipImage call
tempData +='</td>';
它工作正常,但是当它从函数返回时它会改变图像,但我想在flipImage
返回之前改变它
function flipImage(m)
{
var jsonLen = jsonImages.images.length;
var imgNumber = finalImageArray[m];
for(jsn = 0;jsn <jsonLen ;jsn++)
{
if(jsonImages.images[jsn].imageKey== imgNumber)
{
realImage = jsonImages.images[jsn].imagePath;
var element = document.getElementById(m);
// var mg = '<img src="bool.jpg" />'; // change when this line execute what should i put here.?
//element.innerHTML=mg; want like this.
//this is actual code but it change image after returning the function so i don't want this.
element.innerHTML=realImage;
element.setAttribute('src',realImage);
element.setAttribute('onclick', '');
break;
}
}
}
所以我想在flipImage
返回之前更改图像。这只是一个示例代码