html 引入外部JS 点击 按钮 随机展示图片

 

 

 


function displayimg(){
			
			
			
    
			var bodyBgs = [];  //图片地址
			bodyBgs[0] = "images/01.png";
			bodyBgs[1] = "images/02.png";
			bodyBgs[2] = "images/03.png";
			bodyBgs[3] = "images/04.png";
			bodyBgs[4] = "images/05.png";
			bodyBgs[5] = "images/06.png";
			bodyBgs[6] = "images/07.png";
			bodyBgs[7] = "images/08.png";
			bodyBgs[8] = "images/09.png";
			bodyBgs[9] = "images/10.png";
			bodyBgs[10] = "images/11.png";
			bodyBgs[11] = "images/12.png";
			bodyBgs[12] = "images/13.png";
			bodyBgs[13] = "images/14.png";
			bodyBgs[14] = "images/15.png";
			bodyBgs[15] = "images/16.png";
			bodyBgs[16] = "images/17.png";
			bodyBgs[17] = "images/18.png";
			bodyBgs[18] = "images/19.png";
			bodyBgs[19] = "images/20.png";
			bodyBgs[20] = "images/21.png";
			bodyBgs[21] = "images/22.png";
			bodyBgs[22] = "images/23.png";
			bodyBgs[23] = "images/24.png";
			bodyBgs[23] = "images/25.png";

			var randomBgIndex = Math.round( Math.random() * 24 ); //去随机数
			
			
			var obj= document.getElementById('myarea');
			obj.innerHTML = '<img src ="'+bodyBgs[randomBgIndex]+'" />';
			}
    //输出随机的背景图
       // document.write('<style>body{background:url(' + bodyBgs[randomBgIndex] + ') no-repeat 50% 0}</style>');

<!doctype html>
<html>
	<head>
		<title>这是我的第一个标签!</title>
		
		<script  type="text/javascript" src=" js/ce.js "></script>
		<script  type="text/javascript" src=" test2.js "></script>
	</head>
	<body style="text-align:center;">
	
		<div >
		<p id="myarea"></p>
		
		</div>
		 <script>
			test2();
		 </script>
		 <button onclick="displayimg()"> 显示图片 </button>
	</body>
</html>

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乡巴老来编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值