Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中识别图像src是path还是base64字符串_Javascript_Jquery_Image_Base64 - Fatal编程技术网

Javascript 如何在jQuery中识别图像src是path还是base64字符串

Javascript 如何在jQuery中识别图像src是path还是base64字符串,javascript,jquery,image,base64,Javascript,Jquery,Image,Base64,我正在jQuery中处理图像。事实上,我有一个图像标签,有时有src和base 64,如下所示 <img id="profileImage" src="images/blank_photo.png" width="240" height="240" /> 有时图像src将是图像路径 https://lh4.googleusercontent.com/-f87Bg7JWR4A/AAAAAAAAAAI/AAAAAAAAABg/sT5evwC9ziw/photo.jpg 所以问题是

我正在jQuery中处理图像。事实上,我有一个图像标签,有时有src和base 64,如下所示

 <img id="profileImage" src="images/blank_photo.png" width="240" height="240"  />
有时图像src将是图像路径

https://lh4.googleusercontent.com/-f87Bg7JWR4A/AAAAAAAAAAI/AAAAAAAAABg/sT5evwC9ziw/photo.jpg
所以问题是我如何在jQuery中识别它是base64还是映像路径。。。jQuery中是否有任何方法可以识别,或者我们必须使用一般的方法,比如应用if条件和搜索http之类的子字符串


是否有更好的解决方案…

图像的src属性中有base64。要获取src包含base64的对象,请执行以下操作:

var withbase64img = $("img[src*='base64']");
对于循环通过它们:

$("img[src*='base64']").each(function(){
    //code here
});

现在让我们希望不会有任何像
http://server/path/to/something-base64.jpg
..@FrédéricHamidi:在这种情况下,使用
$(“img[src*='/jpeg;base64'])
应该可以。如果是,为什么不匹配
数据:
前缀呢?只有数据URI可以从它开始。
$("img[src*='base64']").each(function(){
    //code here
});