// Complete code of the simple calculator is implemented using js. You can refer to the following suggestions for the shortcomings:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> simple computer </title>
</Head>
<Body>
<Table width = "33%" height = "193" border = "1">
<Tr>
<Td colspan = "4"> <input type = "text" size = "50" name = "result" id = "result"> </td>
</Tr>
<Tr>
<Td width = "24%"> <input type = "button" value = "1" onclick = "getNum (1)"> </td>
<Td width = "23%"> <input type = "button" value = "2" onclick = "getNum (2)"> </td>
<Td width = "26%"> <input type = "button" value = "3" onclick = "getNum (3)"> </td>
<Td width = "27%"> <input type = "button" value = "+" onclick = "getNum ('+')"> </td>
</Tr>
<Tr>
<Td> <input type = "button" value = "4" onclick = "getNum (4)"> </td>
<Td> <input type = "button" value = "5" onclick = "getNum (5)"> </td>
<Td> <input type = "button" value = "6" onclick = "getNum (6)"> </td>
<Td> <input type = "button" value = "-" onclick = "getNum ('-')"> </td>
</Tr>
<Tr>
<Td> <input type = "button" value = "7" onclick = "getNum (7)"> </td>
<Td> <input type = "button" value = "8" onclick = "getNum (8)"> </td>
<Td> <input type = "button" value = "9" onclick = "getNum (9)"> </td>
<Td> <input type = "button" value = "*" onclick = "getNum ('*')"> </td>
</Tr>
<Tr>
<Td> <input type = "button" value = "0" onclick = "getNum (0)"> </td>
<Td> <input type = "button" value = "." onclick = "getNum ('.')"> </td>
<Td> <input type = "button" value = "=" onclick = "getResult ()"> </td>
<Td> <input type = "button" value = "/" onclick = "getNum ('/')"> </td>
</Tr>
</Table>
<Script type = "text/javascript" language = "javascript">
// Determine whether to clear
Var clearContent = false;
// Obtain a number
Function getNum (num ){
If (clearContent ){
// Clear a result if it already exists
Document. getElementById ("result"). value = "";
ClearContent = false;
}
// Obtain the result object
Var objresult = document. getElementById ("result ");
// Implement digital connection
Objresult. value + = num;
}
// Obtain the result object Value
Function getResult (){
Var objresult2 = document. getElementById ("result ");
// Assign values to the result
Objresult2.value = objresult2.value + "=" + eval (objresult2.value );
ClearContent = true;
}
</Script>
</Body>
</Html>
From xweina's column