$(window).resize(function(){ //获得浏览器的宽度 var broswerWidth=$(window).width(); //获得浏览器的高度 var broswerHeight=$(window).height(); $("#desktopPicture").css("height",broswerHeight).css("width",broswerWidth); });
<div id="desktop">
<img id="desktopPicture" src="../images/desktopPicture/img0.jpg" />
</div>
函数可以写在$(document).ready(function(){});中,也可以写在之外.