zoukankan      html  css  js  c++  java
  • 求出数组中所有数字的和&&弹出层效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>求出数组中所有数字的和</title>
    <style>
    body{color:#999;font:12px/1.5 Tahoma;}
    #outer{500px;margin:0 auto;}
    #outer input{padding:3px;border:1px solid #ccc;font-family:inherit;220px;margin-right:10px;}
    .sum{font-size:30px;color:red;}
    </style>
    <script>
    window.onload = function ()
    {
        var oBtn = document.getElementsByTagName("button")[0];
        var oInput = document.getElementsByTagName("input")[0]
        var oStrong = document.getElementsByTagName("strong")[0];
        oInput.onkeyup = function ()
        {
            this.value = this.value.replace(/[^(d)|(,)]/,"")
        }    
        oBtn.onclick = function ()
        {
            var sum = 0;
            var oInput = document.getElementsByTagName("input")[0].value.split(",");
            for (var i in oInput)
            {
                sum += parseInt(oInput[i])
            }
            oStrong.innerHTML = sum
        }
    }
    </script>
    </head>
    <body>
    <div id="outer">
        <label><input type="text" value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" /><span>输入数字求和,数字之间用半角","号分隔</span></label>
        <p><button>求和</button></p>
        <strong class="sum"></strong>
    </div>
    </body>
    </html>

     弹出层效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>弹出层效果</title>
    <style>
    html,body{height:100%;overflow:hidden;}
    body,div,h2{margin:0;padding:0;}
    body{font:12px/1.5 Tahoma;}
    center{padding-top:10px;}
    button{cursor:pointer;}
    #overlay{position:absolute;top:0;left:0;100%;height:100%;background:#000;opacity:0.5;filter:alpha(opacity=50);display:none;}
    #win{position:absolute;top:50%;left:50%;400px;height:200px;background:#fff;border:4px solid #f90;margin:-102px 0 0 -202px;display:none;}
    h2{font-size:12px;text-align:right;background:#FC0;border-bottom:3px solid #f90;padding:5px;}
    h2 span{color:#f90;cursor:pointer;background:#fff;border:1px solid #f90;padding:0 2px;}
    </style>
    <script>
    window.onload = function ()
    {
        var oWin = document.getElementById("win");
        var oLay = document.getElementById("overlay");    
        var oBtn = document.getElementsByTagName("button")[0];
        var oClose = document.getElementById("close");
        oBtn.onclick = function ()
        {
            oLay.style.display = "block";
            oWin.style.display = "block"    
        };
        oClose.onclick = function ()
        {
            oLay.style.display = "none";
            oWin.style.display = "none"    
        }
    };
    </script>
    </head>
    <body>
    <div id="overlay"></div>
    <div id="win"><h2><span id="close">×</span></h2></div>
    <center><button>弹出层</button></center>
    </body>
    </html>
  • 相关阅读:
    黑马程序员JAVA基础Java 集合之Collections 工具类
    黑马程序员JAVA基础Java 集合之Set 接口
    黑马程序员JAVA基础Java 集合之List 集合
    通过回车来完成数据的提交
    BizTalk中多个子记录映射解决办法
    框架的展开与关闭
    一个有用的触发器
    SQL 中分隔字符串的获取
    未保存离开页面要给出提示
    常用的一些javascript小技巧 很实用
  • 原文地址:https://www.cnblogs.com/mayufo/p/4474941.html
Copyright © 2011-2022 走看看