【发布时间】:2012-05-23 07:46:14
【问题描述】:
我正在使用 Mvc 和 jquery,我想知道如何获取要显示的图像。
我有
<img src="@Url.Action("GetImage", "Dashboard")" id="images" alt="image description" width="100" height="72" />
在我的脚本标签中,我有
<script type="text/javascript">
getTheme();
var imageSource = $('#images');
var newimg = $('.logo');
newimg.css({'background-image', 'Url('+imageSource+')'});
</script>
我希望这是来源: 图片不显示,您能帮帮我吗?
【问题讨论】:
-
当您执行 imageSource 时,您将得到
object返回给您,因此当您尝试将imageSource注入为background-image url时,它正在尝试使用一个对象。您需要获取imageSource object的src attribute。这是通过执行类似 -imageSource = imageSource.attr('src')的操作来实现的。然后在var imageSource和var newimg之间插入 - 这会给你想要的效果。
标签: jquery asp.net-mvc model-view-controller