2016-08-24 38 views
0

我試圖追加一個不駐留在我們的服務器上的圖像源以引用和外部服務器。特別是這第四行。在圖像源中追加URL

image of 4th line of code

我需要這個引用外部服務器,而不是默認爲我的默認服務器。和建議?

$(document).ready(function() { 
 
    $('#thumbs ul li').click(function() { 
 
     var imgpath = $(this).attr('dir'); 
 
     $('#image').html('<img src=' + imgpath + '>'); 
 
    }); 
 
    $('.btn').click(function() { 
 
     $('#thumbs').fadeIn(500); 
 
     $('#image').animate({ 
 
      marginTop: '10px' 
 
     }, 200); 
 
     $(this).hide(); 
 
     $('#hide').fadeIn('slow'); 
 
    }); 
 
    $('#hide').click(function() { 
 
     $('#thumbs').fadeOut(500, function() { 
 
      $('#image').animate({ 
 
       marginTop: '50px' 
 
      }, 200); 
 
     }); 
 
     $(this).hide(); 
 
     $('#show').fadeIn('slow'); 
 
    }); 
 
});

回答

1

在img標籤的src屬性是不帶引號的。試試這個:

$('#image').html('<img src="' + imgpath + '">'); 
0

我意識到自己的錯誤,我走了一個不同的方向。而是創建一個名爲「linkpath」的新變量並追加圖像源。

var imgpath = $(this).attr('dir'); 
 
var linkpath = "http://www.website.com"; 
 
$('#image').html('<img src=' + linkpath +/+ imgpath + '>');