【发布时间】:2012-07-23 16:18:16
【问题描述】:
关于 SO 有很多答案显示如何在 jQuery 中使用 .attr 设置 img src。由于某种原因,这不起作用。
<img id="imgMap" style="position:absolute;bottom:7px;right:7px;width:250px;height:250px;" />
<script>
$(function () {
$("#imgMap").attr( 'src', 'http://maps.googleapis.com/maps/api/staticmap?center=41.886456,-87.62325&zoom=14&size=250x250&sensor=false&markers=color:blue%7Clabel:S%7C41.886456,-87.62325');
});
</script>
但是在 HTML 中内联的完全相同的 url 可以正常工作
<img id="imgMap2" runat="server" src="http://maps.googleapis.com/maps/api/staticmap?center=41.886456,-87.62325&zoom=14&size=250x250&sensor=false&markers=color:blue%7Clabel:S%7C41.886456,-87.62325" style="position:absolute;bottom:7px;right:7px;width:250px;height:250px;" />
【问题讨论】:
-
设置 'src' 的 div 元素不会做任何事情。你应该使用 iframe。
-
您的代码在这里可以正常工作jsfiddle.net/r3vvr/2
-
为我工作:jsfiddle.net/kWP6k
标签: jquery