[英]check whether variable in javascript is image url
I am getting json array which contains various name/value pairs. 我正在获取包含各种名称/值对的json数组。 and for every response its different as it comes from database.
对于每个响应,它都与数据库不同。 for every response i get, one name/value pair represents image url info.
对于我得到的每个响应,一个名称/值对代表图像URL信息。 But problem is that name is not constant for all request.
但是问题在于名称对于所有请求而言都不是恒定的。 ie is for one request it can be:
即对于一个请求,它可以是:
'imgurl':'http://l1.yimg.com/071153.jpg'
and for other it can be anything having different name.something like: 对于其他名称可以是具有不同名称的任何东西。
'imginf':'http://lre.ghamg.co.in/arecon.png'
. 'imginf':'http://lre.ghamg.co.in/arecon.png'
I am looking for a way to check whether given variable represents image url(any type of image) using javascript or jquery.i am looking for any good suggestions if they can help me with this. 我正在寻找一种方法来检查给定的变量是否使用javascript或jquery表示图像url(任何类型的图像)。我正在寻找任何好的建议,如果他们可以帮助我的话。
Thanks for stopping by...!! 感谢您的光临... !!
You mean something like this? 你的意思是这样的吗?
var fileName= {"imgurl": ["http://l1.yimg.com/071153.jpg"]};
var file = fileName['imgurl'][0]
var ext = file.substring(file.lastIndexOf('.') + 1);
if(ext ==="gif" || ext === "jpg" || ext === "png"|| ext === "BMP"){
alert('image');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.