更新srcset和src

时间:2018-01-17 02:56:21

标签: javascript jquery responsive-design

如果我使用以下功能。这是更新src和srcset属性的正确方法吗?

<img id="Image" srcset="img/my-large-image.jpg x2" src="img/my-image.jpg" width="500">

$("#Image").one("load", function() {
    //code
}).attr("src", "img/my-new-image.jpg").attr("srcset", "img/my-new-large-image.jpg x2");

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
$("#Image").one("load", function() {
    //code
}).attr("src", "img/my-new-image.jpg").attr("srcset", "img/my-new-large-image.jpg x2");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="Image" srcset="img/my-large-image.jpg x2" src="img/my-image.jpg" width="500">
&#13;
&#13;
&#13;