未找到原稿时显示图像

时间:2013-04-28 16:19:12

标签: javascript image extjs

在JavaScript中,我想在找不到原始图像时显示默认图像。我很确定我会错过一些小东西,但仍然无法弄清楚它是什么。 http://jsfiddle.net/yfm6E/

objImg = new Image();
objImg.src = 'http://tiltips.com/wp-content/uploads/2013/02/imgurlogo.jpeg';


if(!objImg.complete)
 { 
   //  alert('no');
      src = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQGdkmZ9a8Kk-AX1W3wGWZeXnp2OdbSAzqiWnstiFJGg-ZI04Yc'; //load other image
  }else{
   //    alert('yes');
    src= 'http://tiltips.com/wp-content/uploads/2013/02/imgurlogo.jpeg';
  } 



var layout = Ext.create('Ext.panel.Panel', {
            //renderTo: 'layout',
            width: 300,
            height: 300,
            title: 'My Panel', //no title will be blank         
            html: "<img src= src  width='120' height='150'/> ",
            renderTo: Ext.getBody() //get the body and display Layout at there
        });

1 个答案:

答案 0 :(得分:2)

您的src变量是字符串的一部分。因此,请替换此行:

html: "<img src= src  width='120' height='150'/> ",

这一行:

html: Ext.String.format('<img src= "{0}"  width="120" height="150"/> ', src),

此处:http://jsfiddle.net/yfm6E/1/