码迷,mamicode.com
首页 > 其他好文 > 详细

页面加载后累加,自加1&&判断数字是否为两位数

时间:2015-05-03 23:40:00      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

<!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{width: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>

 

页面加载后累加,自加1&&判断数字是否为两位数

标签:

原文地址:http://www.cnblogs.com/mayufo/p/4474982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!