1

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

2 に答える 2

1

これは正常に動作します: http://jsfiddle.net/ypDZw/

于 2012-07-23T16:24:48.783 に答える
0

あなたのコードは私にとってはうまくいきます、ここにリンクがあります:jquery set attribute value

于 2012-07-23T17:07:46.453 に答える