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()方法的使用

    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    包教包会之Open Live Writer设置代码样式
    走近Java之HashMap In JDK8
    走近Java之包装器类Integer
    走近Java之幕后的String
    一点心得
    一个简单的多线程代码实例
    C++实现快速排序
    力扣1025. 除数博弈
    力扣1721. 交换链表中的节点
    力扣1422. 分割字符串的最大得分
  • 原文地址:https://www.cnblogs.com/baixc/p/3428325.html
Copyright © 2011-2022 走看看