2016-08-24 48 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 + '>');