使用jQuery更改img src

时间:2012-07-23 16:18:16

标签: jquery

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;" />

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

你的代码对我来说很好, 这是链接:jquery set attribute value

相关问题