我想动态地添加图像到一个页面。我的HTML包含以下行的代码:动态添加图像jquery
<div class="figuredisplay"></div>
我的CSS中包含的代码下面几行:
.figuredisplay {
width:350px;
height:600px;
padding:10px;
border:5px solid gray;
}
现在,我动态获取图像的位置,并试图在“figuredisplay”添加这些图像。我正在使用jquery来做到这一点。所以,我的代码是这样的:
show_figure= function(figrlocation){
$('.figuredisplay').empty();
var figrhtmlcode='<img src="' + figrlocation + '" width="300" height="300">';
$('.figuredisplay').append(figrhtmlcode);
}
但是没有图像显示在div中。当我尝试
$('.figuredisplay').append(figrlocation);
它正确地在div元素上显示图形位置(在磁盘上)。在做了一些搜索之后,我尝试了
$('<img src="'+ figrlocation +'">').load(function() {
$(this).width(300).height(300).appendTo('.figuredisplay');
});
以及没有运气。任何一点我做错了什么?任何帮助将不胜感激。
适合我.. http://jsfiddle.net/errYD/ –