写了半天的JavaScript随机背景图代码,没想到网上有现成的Emlog插件,也罢,留着备份自用。

<!-- 背景图-->
<script type="text/javascript">
var bodyBgs = [];
	bodyBgs[0] = "<?php echo TEMPLATE_URL; ?>images/bg/0.png";
	bodyBgs[1] = "<?php echo TEMPLATE_URL; ?>images/bg/1.png";
	bodyBgs[2] = "<?php echo TEMPLATE_URL; ?>images/bg/2.png";
	bodyBgs[3] = "<?php echo TEMPLATE_URL; ?>images/bg/3.png";
	bodyBgs[4] = "<?php echo TEMPLATE_URL; ?>images/bg/4.png";
	bodyBgs[5] = "<?php echo TEMPLATE_URL; ?>images/bg/5.png";
	bodyBgs[6] = "<?php echo TEMPLATE_URL; ?>images/bg/6.png";
	bodyBgs[7] = "<?php echo TEMPLATE_URL; ?>images/bg/7.png";
	bodyBgs[8] = "<?php echo TEMPLATE_URL; ?>images/bg/8.png";
	bodyBgs[9] = "<?php echo TEMPLATE_URL; ?>images/bg/9.png";
var randomBgIndex = Math.round( Math.random() * 9 );
        document.write('<style>body{background:url(' + bodyBgs[randomBgIndex] + ')}</style>');
</script>