var str = '/demo/img1.jpg' //str为img 图片地址 <script> $(function () { $("#img").attr("src",str) }) </script> <div> <img id="img" src="/demo/img3.jpg"> </div>