我想知道如果有方法將它打印在計算按鈕下的同一頁上的文本字段中,而不是使用alert函數來顯示函數結果。以下是我迄今爲止:如何在同一頁面上顯示javascript結果
<!DOCTYPE html>
<html>
<head>
\t <title></title>
\t <link rel="stylesheet" type="text/css" href="styles/formula_styles.css">
\t <script type="text/javascript">
\t \t var a,b,c;
\t \t function setValues1()
\t \t {
\t \t \t a = Number(document.getElementById("a").value);
\t \t \t b = Number(document.getElementById("b").value);
\t \t \t c = Number(document.getElementById("c").value);
\t \t }
\t \t function and()
\t \t {
\t \t \t setValues1();
\t \t \t result1 = (-b + Math.sqrt(b*b -4*a*c))/(2*a);
\t \t \t result2 = (-b - Math.sqrt(b*b -4*a*c))/(2*a);
\t \t \t alert("The volume of this cube is " +result1 + " and " +result2);
\t \t }
\t </script>
</head>
<body>
<nav>
\t <a href="index.html">Home</a> // <a href="levels.html">Grade Levels</a>
</nav>
<div id="container">
\t <div id="formula"> \t
\t \t <input type="text" id="a" placeholder="'A' Variable"/><br>
\t \t <input type="text" id="b" placeholder="'B' Variable"/><br>
\t \t <input type="text" id="c" placeholder="'C' Variable"/><br>
\t \t <input type="button" onclick="and()" value="Calculate!"/>
\t </div>
</div>
</body>
</html>
您可能需要狀態你有什麼問題。 – mhs