我仍在使用JavaScript編碼的計算器。我問這個問題,我該如何使它停止顯示輸出警報,並將其打印到名爲「Output」下面的div標記中。將警報更改爲打印輸出
我已經放在我認爲這將是在輸出和我有這樣的粘貼下面:
<html>
<head>
<link href="stylesheet/stylesheet.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function checkinputs(){
var A = parseInt(document.triangleform.input1.value);
var B = parseInt(document.triangleform.input2.value);
var C = parseInt(document.triangleform.input3.value);
if (A == B && B == C) { alert("Equalateral"); }
if (A == B && B != C || B == C && A != B || C == A && A != B) {alert("Isosceles");}
if (A != B && B != C && C != A) {alert("Scalene!");}
}
function keypress(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[0-9]|\./;
if(!regex.test(key)) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
function notEmpty(field, NocharMsg){
if(field.value.length == 0){
alert(NocharMsg);
field.focus();
return false;
}
return true;
}
</script
</head>
<body>
<div id="Container">
<div id="Header"><h1></h1></div>
<div id="Content_1">
<div id="Explanation">
This calculator will determine what
triangle you have made depending on
the integer values in the input fields.
</div>
<div id="Form">
<FORM NAME="triangleform">
Enter the triangle values below: <br>
<p>
<h4>Side 1: </h4><BR>
<INPUT TYPE="Integer" NAME="input1" onkeypress='keypress(event)' /><P>
<h4>Side 2: </h4><BR>
<INPUT TYPE="Integer" NAME="input2" onkeypress='keypress(event)' /><P>
<h4>Side 3:</h4> <BR>
<INPUT TYPE="Integer" NAME="input3" onkeypress='keypress(event)' /><P>
<INPUT TYPE="button" NAME="Submit" Value="Submit" onClick="checkinputs()" />
</FORM>
</div>
<div id="Verbal_Output">
<h2>You made a:</h2>
<p>
<h2>Triangle</h2>
</div>
</div>
<p>
<p>
<div id="Content_2">
<div id="Output">
<script>
document.getElementById("Output").value = checkinputs();
</script>
</div>
</body>
</html>
非常感謝你。
因此,而不是它是'{警報( 「名稱」);}'這將是 '如果(A = B && B = C && C = A!!!){回報;}? ' '
增加了一個例子,希望有所幫助。 –
謝謝克里斯,我只是改變了你的功能(重新寫它自己學習),並改變了div: '