Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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 拉斐尔画布中的图像回退_Javascript_Jquery_Image_Raphael_Fallback - Fatal编程技术网

Javascript 拉斐尔画布中的图像回退

Javascript 拉斐尔画布中的图像回退,javascript,jquery,image,raphael,fallback,Javascript,Jquery,Image,Raphael,Fallback,我必须绘制一些图像(使用for循环),如果找不到正确的图像,我想加载一个备用图像 我的javascript: var image = paper_layer.image(image_selected, x, y, width, height); $('image').one('error', function () { console.log('image not found') image_selected='/my_path/not_found.png' va

我必须绘制一些图像(使用for循环),如果找不到正确的图像,我想加载一个备用图像

我的javascript:

var image = paper_layer.image(image_selected, x, y, width, height);
$('image').one('error', function () {    
    console.log('image not found')
    image_selected='/my_path/not_found.png'
    var image = paper_layer.image(image_selected, x, y, width, height);
});
问题是,当丢失图像时,此函数会为每个图像(即使是找到的图像)添加一个回退图像

我也试过了,但不起作用(没有回退显示,控制台上没有显示消息
'image not found'
):


PS:我使用的是Raphael

纸张层。图像
不返回HTMLImageElement对象,而是某种Raphael对象


但是,它似乎包含对键0下实际图像元素的引用-因此请尝试
image[0]。onerror=…
,它应该正确地将错误处理程序绑定到实际的HTML图像元素。

paper\u layer.image
不会返回HTMLImageElement对象,而是某种Raphael对象,但是,它似乎包含对键0下实际图像元素的引用-因此请尝试
image[0]。onerror=…
现在它可以工作了,谢谢!好的,太好了,这是一个简短的回答。
var image = paper_layer.image(image_selected, x, y, width, height);
image.onerror=function () {
    console.log('image not found')
    image_selected='/my_path/not_found.png'
    var image = paper_layer.image(image_selected, x, y, width, height);
};