0
我在做一個帶有Javascript的程序。我必須在這個程序中做一些操作,最後,我必須在表單中顯示結果。在html表單中顯示變量的內容(javascript)
我該怎麼辦?我認爲也許我必須在「id」或「value」參數中加入某些內容,但是,我不確定!
謝謝!
這裏我讓你看看我的一些代碼。 (這不是所有的代碼,這只是一部分,我認爲在什麼我質疑影響)
function loadPage()
{ \t
\t var divContent = "<br/>This is a calculator. Introcuce 2 numbers and an operator. ";
\t divContent += "<input type = 'text' id='number1' value='0'/> ";
divContent += "<input type = 'text' id='operator' value=''/> ";
divContent += "<input type = 'text' id='number2' value='0'/>";
\t divContent += "<input type = 'button' value='operations' onclick='operations()'/>";
\t
\t document.getElementById("content").innerHTML += divContent;
}
\t
function operations()
{
\t
\t var number1 = document.getElementById("number1").value;
var operator = document.getElementById("operator").value;
var number2 = document.getElementById("number2").value;
\t var divContent="<br><br><br> RESULT: ";
switch(operator)
{
case '+':
result = number1 + number2;
var divContent="The result of "+ number1 +" + "+number2+" = ";
divContent += "<input type = 'text' id='operator' value=''/>";
break;
}
}