JS练习之改善用户体验,弹出登录窗口(4 位领导批示)

Demo www.qqdang.net/code/myAlert/

Code

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>弹出提示</title>
  6. <style>
  7. * {margin:0;padding:0;font-size:12px;}
  8. html,body {height:100%;width:100%;}
  9. #content {background:#f8f8f8;padding:30px;height:100%;}
  10. #content a {font-size:30px;color:#369;font-weight:700;}
  11. #alert {border:1px solid #369;width:300px;height:150px;background:#e2ecf5;z-index:1000;position:absolute;display:none;}
  12. #alert h4 {height:20px;background:#369;color:#fff;padding:5px 0 0 5px;}
  13. #alert h4 span {float:left;}
  14. #alert h4 span#close {margin-left:210px;font-weight:500;cursor:pointer;}
  15. #alert p {padding:12px 0 0 30px;}
  16. #alert p input {width:120px;margin-left:20px;}
  17. #alert p input.myinp {border:1px solid #ccc;height:16px;}
  18. #alert p input.sub {width:60px;margin-left:30px;}
  19. </style>
  20.  
  21. </head>
  22.  
  23. <body>
  24. <div id="content">
  25. <a href="#">注册</a>
  26. </div>
  27. <div id="alert">
  28. <h4><span>现在注册</span><span id="close">关闭</span></h4>
  29. <p><label>用户名</label><input type="text" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
  30. <p><label>密 码</label><input type="password" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
  31. <p><input type="submit" value="注册" class="sub" /><input type="reset" value="重置" class="sub" /></p>
  32. </div>
  33. <script type="text/javascript">
  34. var myAlert = document.getElementById("alert");
  35. var reg = document.getElementById("content").getElementsByTagName("a")[0];
  36. var mClose = document.getElementById("close");
  37. reg.onclick = function()
  38. {
  39. myAlert.style.display = "block";
  40. myAlert.style.position = "absolute";
  41. myAlert.style.top = "50%";
  42. myAlert.style.left = "50%";
  43. myAlert.style.marginTop = "-75px";
  44. myAlert.style.marginLeft = "-150px";
  45.  
  46. mybg = document.createElement("div");
  47. mybg.setAttribute("id","mybg");
  48. mybg.style.background = "#000";
  49. mybg.style.width = "100%";
  50. mybg.style.height = "100%";
  51. mybg.style.position = "absolute";
  52. mybg.style.top = "0";
  53. mybg.style.left = "0";
  54. mybg.style.zIndex = "500";
  55. mybg.style.opacity = "0.3";
  56. mybg.style.filter = "Alpha(opacity=30)";
  57. document.body.appendChild(mybg);
  58. document.body.style.overflow = "hidden";
  59. }
  60.  
  61. mClose.onclick = function()
  62. {
  63. myAlert.style.display = "none";
  64. mybg.style.display = "none";
  65. }
  66. </script>
  67. </body>
  68. </html>

相关文章

分享到新浪微博 推荐到豆瓣 分享到 Google Reader 加入Google书签 嘀咕一下 分享到饭否 分享到做啥 分享到叽歪 分享到鲜果 加入QQ书签 加入百度搜藏 加入雅虎书签 分享到垦一垦

  1. 4
    银子

    浏览器兼容问题..好似我写这个时只有IE7与FF2 -_-#

  2. 3
    林枫

    加了document.body.style.overflow = “auto”;还是不行,高手帮忙~~!!

  3. 2
    银子

    @sinnow

    mClose.onclick = function()
    {
    myAlert.style.display = “none”;
    mybg.style.display = “none”;
    }

    绑定事件里加上一句

    document.body.style.overflow = “auto”;

    因为是练习做的.没想那么周全-__!!

  4. 1
    sinnow

    用了您的代码后发现个问题啊,不登录的情况下点关闭,浏览器的滚动条也没有了,怎么才能把那个滚动条显示出来啊!

请领导指示

验证码 (必须)

Additional comments powered by BackType

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志