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" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style>
        *{margin: 0px;padding: 0px;}
        body{font-size: 13px;padding: 100px;}
        input[type=text]{width: 60px;height: 26px;line-height: 26px;background-color: #eee;border: 1px solid #ccc;}
        input[type=button]{padding: 5px 15px;}
        h2{color: red;display: inline-block;}
    </style>
    <script>
        window.onload=function(){
            var aInput = document.getElementsByTagName('input');
            var oBtn = document.getElementById('btn');
            var oH = document.getElementsByTagName('h2')[0px];
    
            for(var i=0;i<aInput.length-1;i++){
                aInput[i].onkeyup=function(){
                    this.value = this.value.replace(/[^d]/,'');
                }
            }
    
            oBtn.onclick=function(){
                (aInput[0].value==''||aInput[1].value=='')?
                alert('请输入数字'):
                (oH.innerText = Math.max(aInput[0].value,aInput[1].value));
            }
        }
    </script>
    </head>
    <body>
        <input type="text" />
        <strong>VS</strong>
        <input type="text" />
        <input id="btn" type="button" value="最大数是>>>" />
        <h2></h2>
    </body>
    </html>

    结果如下图所示:

    Math.max()方法的使用

    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    php aes128加密
    redis应用场景
    Yii2开发小技巧
    yii2开启事务
    yii2验证密码->手机号码短信发送>手机短信发送频繁问题
    yii2 rules验证规则,ajax验证手机号码是否唯一
    随笔20170415
    v1版本
    数的划分
    单词接龙
  • 原文地址:https://www.cnblogs.com/baixc/p/3428325.html
Copyright © 2011-2022 走看看