2013-04-28 85 views
0

在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 
     }); 

回答

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/

+0

太謝謝你了! – Noon 2013-04-28 16:57:51