zoukankan      html  css  js  c++  java
  • 实训篇-JavaScript-陶渊明去没去过桃花源

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    		<!--定义样式-->
    		<style type="text/css">
    			/*id选择器 定义div的大小 背景色*/
    			#div1{
    				 300px;
    				height: 200px;
    				background-color:cornflowerblue;
    				border: solid 1px black;
    				/*上边距*/
    				margin-top: 50px;
    				/*左边距*/
    				margin-left: 600px;
    				text-align: center;
    				
    			}
    			/*元素选择器*/
    			input{
    				 70px;
    				height: 50px;
    				margin-left: 20px;
    				color: red;
    			}
    		</style>
    		<script type="text/javascript">
    			//随机生成div新的位置
    			function random(){
    				//得到div
    				var div1=document.getElementById("div1");
    				//随机得到两个边距的值
    				var left=Math.random()*1200;
    				var top=Math.random()*500;
    				div1.style.marginLeft=left+"px";
    				div1.style.marginTop=top+"px";
    				
    			}
    			//隐藏div并设置页面的背景图片
    			function test(){
    				//设置body的背景图片
    				document.body.style.backgroundImage="url(img/background.jpg)"
    				//隐藏
    				var div1=document.getElementById("div1");
    				div1.style.display="none";
    			}
    		</script>
    	</head>
    	<body>
    		<!--块-->
    		<div id="div1">
    			陶渊明去没去过桃花源?
    			<br /><br />
    			<input type="button" name="" id="" value="去过" onclick="test()" />
    			<!--当鼠标的位置 移动到‘没去过’按钮的时候 触发方法 重新生成div的位置-->
    			<input type="button" name="" id="" value="没去过"  onmouseover="random()"/>
    		</div>
    	</body>
    </html>
    

      

  • 相关阅读:
    NSOperation, NSOperationQueue 原理探析
    BAT面试的准备—iOS篇
    iOS 导航栏
    iOS应用性能调优的25个建议和技巧
    iOS 性能调优
    构造方法
    属性和成员变量
    iOS消息推送机制
    大道至简,回归到梦开始的地方。人生如此,编程亦如此。
    尊重生存在这个世界上的每一个人(转)
  • 原文地址:https://www.cnblogs.com/52dxer/p/12165192.html
Copyright © 2011-2022 走看看