页面加载后累加,自加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{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>

 

posted @ 2015-05-03 23:05  mayufo  阅读(346)  评论(0编辑  收藏  举报