There will undoubtedly be a jQuery solution posted soon enough. To do it without, the following will work:
function getImagesByAlt(alt) {
var allImages = document.getElementsByTagName("img");
var images = [];
for (var i = 0, len = allImages.length; i < len; ++i) {
if (allImages[i].alt == alt) {
images.push(allImages[i]);
}
}
return images;
}
var myImage = getImagesByAlt("Myimage")[0];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…