如何在JavaScript中检查图像源 [英] How to check image source in javascript
本文介绍了如何在JavaScript中检查图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我的桌子上有两个图像(正确或错误),我只想在正确的图像上显示警报?
我用了这段代码..
var td4 = document.createElement(''td'');
Hi
i have two image(correct or error ) in my table , i want to show alert only on correct image ?
i used this code..
var td4 = document.createElement(''td'');
var img = document.createElement('img');
img.setAttribute('width', '24');
img.setAttribute('height', '24');
td4.setAttribute('style','width:3%');
td4.setAttribute('align','center');
(function(id) {
img.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
// now it will alert the id (what is the i of the for-loop):
if( img.attr('src')== "images/correct-icon.png")
alert(id);
};
}(i));
if(serviceAlertPresent[i].firstChild.nodeValue == 'false'||otherAlertPresent[i].firstChild.nodeValue == 'false')
{
img.src='images/correct-icon.png';
//td4.innerHTML = "<img src=\"images/correct-icon.png\" width=\"20\" height=\"20\" />";
td5.innerHTML="";
}
else
{
img.src='images/error-msg.png';
//td4.innerHTML = "<img src=\"images/error-msg.png\" width=\"20\" height=\"20\" />";
td5.innerHTML=expDepart[i].firstChild.nodeValue ;
}
td4.appendChild(img);
警报ID未显示...?
如何显示id ..
alert Id is not display...?
How to display id..
推荐答案
hi 查看以下内容
link1 [ link2 [
hi check out the following
link1[^]
link2[^]
这篇关于如何在JavaScript中检查图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文