js练习题三:使div变色 密码提示框

<style type="text/css">
	#tip{
		border:2px #ff9900 solid;
		background:#ffffcc;
		width:200px;
		height:80px;
		display:none;
	}

  </style>
 </head>
 <body>
  <div id="outer" class="">
	<input type="radio" name="">一周内自动登录
  <div id="tip" class="">
	为了您的个人信息安全,请不要在网吧或公用电脑上使用此功能!
  </div>
  </div>
 </body>
 <script type="text/javascript">
 window.onload=function(){
 var x=document.getElementById("outer");
  var y=document.getElementById("tip");

 x.onmouseout=function(){y.style.display="none";}
  x.onmouseover=function(){y.style.display="block";}

}
 </script>
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html"><pre name="code" class="html"><style type="text/css">
	#outer{
	width:300px;
	height:120px;
	text-align:center;
	}
	.D{
	width:80px;
	height:80px;
	float:left;
	margin:10px;
	background:green;
	}
  </style>
 </head>
 <body>
  <div id="outer" class="">
		<div id="" class="D">
	
	  </div>
	  <div id="" class="D">
		
	  </div>
	  <div id="" class="D">
		
	  </div>
  </div>
  <button>变色</button>
 </body>
 <script type="text/javascript">
 window.onload = function (){
    var oDiv = document.getElementById("outer").getElementsByClassName("D");
    var oBtn = document.getElementsByTagName("button")[0];
    oBtn.onclick = function (){
        for(var i = 0; i < oDiv.length; i++) 
            oDiv[i].style.background = "pink";
    }
}
 </script>





以上为原生js代码
若换使用jquery
代码可改写为

$(document).ready(function(){
  $("#outer").mouseover(function(){$("#tip").css("display","block");});
  $("#outer").mouseout(function(){$("#tip").css("display","none");});
});
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值