且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

每次刷新页面时如何更改背景图像?

更新时间:2022-06-10 05:03:23

试试这样..





Try like this..


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">
       var loading = function () {
            var totalCount = 6;
            var num = Math.floor(Math.random() * totalCount) + 1
            document.body.background = 'images/' + num + '.jpg'

        }
    </script>
</head>
<body onload=loading();>
    <form id="form1" runat="server">

    </form>
</body>
</html>


尝试



Try

<html>
<head>
<script type="text/javascript">
var totalCount = 6;
function ChangeIt()
{
var num = Math.ceil( Math.random() * totalCount );
document.getElementById('background-container').style.background = 'images/'+num+'.jpg';

}
</script>
</head>
<body onload='ChangeIt()'>

</body>
</html>