比较JavaScript中的图片 [英] Compare an image in javascript

查看:79
本文介绍了比较JavaScript中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较javascript中的图片.如果图像为真,它将更改为其他图像.我写了一个if语句,但它似乎不起作用.有谁知道我怎么能做到这一点?

I am trying to compare an image in javascript. If the image is true it will change to a different image. I wrote an if statement but it doesn't seem to work. Does anyone know how I can achieve this?

function test()
{
imageElement = document.getElementById('pic');
if(imageElement.src == "images/cat_12.gif"){

imageElement.src = "images/press2_12.gif";
}else{

}
}

推荐答案

function test(){
    if(imageElement.src.indexOf("images/cat_12.gif") != -1){
       //
    }
}

这篇关于比较JavaScript中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆