?? 6-1 由初速度和仰角求射程.htm
字號:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>6-1 由初速度和仰角求射程</title>
<!-- 腳本部分 -->
<script>
//計算射程的函數(shù)
function calc(){
//聲明所用到的變量
var lngSpeed, lngAngle, lngTime, lngDistance, g;
//重力加速度
g = 10;
//獲取用戶輸入的數(shù)值
lngSpeed = $("txt_init_speed").value;
lngAngle = $("txt_angle").value;
//判斷用戶輸入是否完整
if(lngSpeed == "" || lngAngle ==""){
alert("輸入信息不全,請輸入未完成項。");
return;
}
//判斷用戶輸入是否是數(shù)值
if(isNaN(lngSpeed) || isNaN(lngAngle)){
alert("輸入有誤!內(nèi)容必須是數(shù)值,請重新輸入。");
return;
}
//計算炮彈飛行的時間
lngTime = Math.sin(lngAngle/180*Math.PI)*lngSpeed/g*2;
//計算炮彈的射程
lngDistance = lngTime*Math.cos(lngAngle/180*Math.PI)*lngSpeed;
//將結(jié)果以文本框的數(shù)值輸出
$("txt_time").value = lngTime.toFixed(2);
$("txt_distance").value = lngDistance.toFixed(2);
}
function $(str){ return(document.getElementById(str)); }
</script>
</head>
<body style="overflow:auto;">
<table>
<tr>
<td>炮彈的初速度:</td>
<td><input id="txt_init_speed">(米/秒)</td>
</tr>
<tr>
<td>炮彈的發(fā)射仰角:</td>
<td><input id="txt_angle">(度)</td>
</tr>
<tr>
<td><input type="button" value="計算" onclick="calc();"></td>
</tr>
<tr>
<td>炮彈的飛行時間:</td>
<td><input id="txt_time">(秒)</td>
</tr>
<tr>
<td>炮彈的射程:</td>
<td><input id="txt_distance">(米)</td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -