【问题标题】:change img src with jQuery用 jQuery 改变 img src
【发布时间】: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;" />

【问题讨论】:

标签: jquery


【解决方案1】:

【讨论】:

  • 网址中有一个字母错字 - 我会接受,因为这些其他答案非常糟糕
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2011-09-27
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 2010-12-22
    相关资源
    最近更新 更多