js练习题三:使div变色 密码提示框
2016-04-11 21:12
501 查看
<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");});});
相关文章推荐
- 浅谈javascript的this指向
- JavaScript中数组和字符串的方法以及互相转换
- Javascript的9张思维导图学习
- Javascript的9张思维导图学习
- 关于火狐和IE下href="javascript:void(0)"兼容性的问题
- Effective JavaScript Item 35 使用闭包来保存私有数据
- Python实现Json结构对比的小工具兼谈编程求解问题
- 浏览器加载和渲染html的顺序(html/css/js)
- 浏览器加载和渲染html的顺序(html/css/js)
- jsp页面中的$(param.xxxxx)
- JS中把函数作为另一函数的参数传递总结
- JavaScript 项目实战工具类
- JS 基础回顾(一)
- js练习题二:函数接收
- [BZOJ2257][Jsoi2009]瓶子和燃料
- 关于JS出现的Cannot read property 'XXX' of null错误
- qt+evaluatejavascript
- js和qt4 evaluteJavascript
- js练习题:网页换肤
- 获取前端post方式传过来的JSON格式的数据的代码