2016-08-24 10 views
0

私たちのサーバ上に存在しない画像ソースを、参照と外部サーバに追加しようとしています。特にこの4行目。Javascript添付画像ソースの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 + '>');