zoukankan      html  css  js  c++  java
  • 页面加载后累加,自加1&&判断数字是否为两位数

    <!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>页面加载后累加,自加1</title>
    <style>
    body{text-align:center;font:700 30px/1.5 arial;}
    </style>
    <script>
    window.onload = function ()
    {
        var oBody = document.body;
        var i = 0;
        setInterval(updateNum, 1000);
        updateNum();
        function updateNum()
        {
            oBody.innerHTML = ++i    
        }
    }
    </script>
    </head>
    <body>
    </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>
    body{font:12px/1.5 arial;text-align:center;}
    .f-text{50px;border:1px solid #ccc;background:#f0f0f0;font-family:inherit;padding:3px;margin-right:10px;}
    </style>
    <script type="text/javascript">
    window.onload = function ()
    {
        var aInput = document.getElementsByTagName("input");
        var aSpan = document.getElementsByTagName("span")[0];
        var i = 0;
        
        aInput[0].onkeyup = function ()
        {
            this.value = this.value.replace(/[^d]/,"")
        }
        
        aInput[1].onclick = function ()
        {
            (aInput[0].value == "") ?
            alert("请输入数字!") :
            alert(/^d{2}$/.test(parseInt(aInput[0].value)) ? "√ 是两位数" : "这是" + aInput[0].value.length + "位数");
        }
    };
    </script>
    </head>
    <body>
    <input type="text" class="f-text" /><input type="button" value="是否为两位数" />
    </body>
    </html>
  • 相关阅读:
    angularJs实现星星等级评分
    angular自定义过滤器在页面和控制器中的使用
    字符串单个替换
    angular中的$cookies和$cookieStore设置过期时间
    DOM操作和jQuery实现选项移动操作
    PHP 中英文混排截取字符串
    固定格式时间转换时间戳
    PHP生成唯一订单号的方法汇总
    MySQL优化索引及优化汉字模糊查询语句
    简单封装数据库类
  • 原文地址:https://www.cnblogs.com/mayufo/p/4474982.html
Copyright © 2011-2022 走看看