JavaScriptコードも含まれているhtmlコードで作業していますが、プログラムは動作しますが、必要な結果がすぐに得られ、1つの瞬間に消去されます問題はjavascriptコードに根ざしていません)。私が必要とするのは、それらの結果を画面上で一時停止し、消去しないことです。コードは次のとおりです。javascriptコードを含むhtmlで速すぎる結果
<html>
<head>
<title>Geometric operations</title>
<script>
function Calculate(){
var radius=document.forms["form1"]["radius"].value;
if (radius==null || radius=="" || isNaN(radius)){
alert("Please give the radius of the circle");
return false;
}
var radius = parseInt(document.getElementById("radius").value,5);
var perimeter = (2 * radius * Math.PI);
var embadon = (radius * radius * Math.PI);
document.getElementById("perimeter").value = perimeter;
document.getElementById("embadon").value = embadon;
}
</script>
</head>
<body>
<h1>Calculation of circle perimeter and circle area</h1>
To calculate the circle perimeter and circle area you need to give the radius and then press the button<b>"Calculation"</b><br>
<form name="form1" action="" method="" onSubmit="return Calculate()">
<pre>
Circle radius : <input type="text" id="radius" size=5> m<br>
Circle perimeter : <input type="text" id='perimeter' size=5> m <br>
Circle area : <input type="text" id='embadon' size=5> m^2<br>
<input type="submit" name="submit" value="Calculation" onclick="Calculate()">
</pre></form>
</body>
</html>
これがなぜ起こるかについての事前のおかげで、ありがとうございます。
送信ボタンはもちろん、ページを再読み込みした、押したときにあなたがあなたのフォームを提出しています。この場合もフォームの提出を防ぐ必要があります。または、最初に適切なタイプのボタンを選択してください。 – CBroe
@CBroe - それは私の初期の考えでしたが、 'onSubmit =" return Calculate() "と' return false; '...ああ、それはifステートメントにあります。押し込みが混乱しています。 – Quentin
素早く答えてくれてありがとう@CBroe私はそれを試してみましょう。 – Newer