通过html在对象中显示图像。JQuery
我正在html页面上显示从本地存储中的对象获取的信息。H2、H5和p都能通过,但我无法获得图像。有什么想法吗?代码显示了Jquery和html,我使用它们将信息拉入页面通过html在对象中显示图像。JQuery,jquery,html,object,local-storage,Jquery,Html,Object,Local Storage,我正在html页面上显示从本地存储中的对象获取的信息。H2、H5和p都能通过,但我无法获得图像。有什么想法吗?代码显示了Jquery和html,我使用它们将信息拉入页面 //JQuery function displayPageContent(object){ if(object){ $('#bar-info h2').html(object.barname); $('#bar
//JQuery
function displayPageContent(object){
if(object){
$('#bar-info h2').html(object.barname);
$('#bar-info h5').html(object.address);
$('#bar-info p').html(object.description);
$('#bar-info img src').html(object.image);
}
}
displayPageContent(pageBar);
//HTML
<div class="content">
<div id="bar-info">
<center><h2></h2></center>
<h5></h5>
<p></p>
<img scr="">
</div>
//JQuery
函数displayPageContent(对象){
如果(对象){
$('#bar info h2').html(object.barname);
$('#bar info h5').html(object.address);
$('#bar info p').html(object.description);
$('#bar info img src').html(object.image);
}
}
显示页面内容(页面栏);
//HTML
您需要设置.attr()
。像这样:
$('img').attr('src','image src') $('#bar info img src').html(object.image)
将选择名为src
的元素并设置其html
您要设置
img
的src
属性:$('#bar info img').attr('src',object.image)代码>console.log(object.image)
是否显示图像信息?是的,它显示图像信息…这已经起作用了谢谢:)酷!如果成功了,一定要接受这个答案,以帮助那些提出同样问题的人。