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

勾股定理

时间:2019-01-25 14:11:06      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:oct   onkeyup   nbsp   ntb   document   判断   tle   ==   head   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input type="text" value="" id="num1"/>
        <span>+</span>
        <input type="text" value="" id="num2"/>
        <span>=</span>
        <input type="text" value="" id="num3"/>
    </body>
</html>
<script>
    var oNum1 = document.getElementById( "num1" );
    var oNum2 = document.getElementById( "num2" );
    var oNum3 = document.getElementById( "num3" );
    //判断num1和num2是否为空
    function num(){
if( oNum1.value == "" || oNum2.value == ""){
   oNum3.value = "输入的数值不能为空"
}else{
oNum3.value = Math.sqrt(Math.pow((oNum1.value),2)+Math.pow(Number(oNum2.value),2));
}
    }
    oNum1.onfocus = function(){
        num();
            oNum2.onfocus = function(){
                num();
            }
    }
oNum2.onkeyup = function(){
      num();
            oNum1.onkeyup = function(){
                num();
            }
}

</script>

勾股定理

标签:oct   onkeyup   nbsp   ntb   document   判断   tle   ==   head   

原文地址:https://www.cnblogs.com/tis100204/p/10319237.html

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