<!DOCTYPE html>


<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>连轴器找中心测试网页</title>
<style>    
    
</style>


<form action="" method="post" name="myform" id="myform">
    <div class="wrapper" id="_wrapper"> 
        直径:<input type="text" name="radius" id="radius" autocomplete="off"/><br><br>
        前脚:<input type="text" name="ffoot" id="ffoot" autocomplete="off"/><br><br>
        后脚:<input type="text" name="rfoot" id="rfoot" autocomplete="off"/><br><br>
        上偏:<input type="text" name="utran" id="utran" autocomplete="off"/><br><br>
        上夹角1:<input type="text" name="uang1" id="uang1" autocomplete="off"/><br><br>
        上夹角2:<input type="text" name="uang2" id="uang2" autocomplete="off"/><br><br>
        下偏:<input type="text" name="dtran" id="dtran" autocomplete="off"/><br><br>
        下夹角1:<input type="text" name="dang1" id="dang1" autocomplete="off"/><br><br>
        下夹角2:<input type="text" name="dang2" id="dang2" autocomplete="off"/><br><br>
        <input type="button" value="计算" id="" onclick="jisuan()"/>
        <input type="reset" value="重置" id="" /><br><br>
        前脚垫片:<input name="txtResult1" type="text" id="txtResult1" autocomplete="off"/>
        后脚垫片:<input name="txtResult2" type="text" id="txtResult2" autocomplete="off"/>
        
    </div>
</form>

<script>
    
    var rad = 0;
    var ff = 0;
    var rf = 0;
    var ut = 0;
    var u1 = 0;
    var u2 = 0;
    var dt = 0;
    var d1 = 0;
    var d2 = 0;
    var txtResult1= 0;
    var txtResult1= 0;
    
        
    //点击事件    //document.form的name值.input的name值.value
    function jisuan(){
        rad = parseFloat(document.myform.radius.value);
        ff = parseFloat(document.myform.ffoot.value);
        rf = parseFloat(document.myform.rfoot.value);
        ut = parseFloat(document.myform.utran.value);
        u1 = parseFloat(document.myform.uang1.value);
        u2 = parseFloat(document.myform.uang2.value);
        dt = parseFloat(document.myform.dtran.value);
        d1 = parseFloat(document.myform.dang1.value);
        d2 = parseFloat(document.myform.dang2.value);            
        document.myform.txtResult1.value=(((dt-ut)/2)-(((d1+d2-u1-u2)/2)*ff/rad));
        document.myform.txtResult2.value=(((dt-ut)/2)-(((d1+d2-u1-u2)/2)*rf/rad));
        //判断文本框是否为空
        //注意此处文本框获取值时使用了parseFloat转换,所以当文本框为空时是NaN,并不是""和null,所以需要用到isNaN来判断。
        if(isNaN(rad) && isNaN(ff) && isNaN(rf) && isNaN(ut) && isNaN(u1) && isNaN(u2) && isNaN(dt) && isNaN(d1) && isNaN(d2)){
            alert("请填写数据!");
        }
        else if(isNaN(rad)){
            alert("请填写直径!");
        }
        else if(isNaN(ff)){
            alert("请填写前脚距离!");
            }
        else if(isNaN(rf)){
            alert("请填写后脚距离!");
            }
        else if(isNaN(ut)){
            alert("请填写上偏数据!");
            }
        else if(isNaN(u1)){
            alert("请填写上夹角1!");
            }
        else if(isNaN(u2)){
            alert("请填写上夹角2!");
            }
        else if(isNaN(dt)){
            alert("请填写下偏数据!");
            }
        else if(isNaN(d1)){
            alert("请填写下夹角1!");
            }
        else if(isNaN(d2)){
            alert("请填写下夹角2!");
        }
    }

</script>