JS simple calculator instance, js Calculator
This article describes how to implement a simple JavaScript calculator. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows:
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript">
Function sum (){
// Js type conversion parseInt (value, 10) means converting the value to a decimal value.
Var id1 = parseInt (document. getElementById ("bnt1"). value, 10 );
Var id2 = parseInt (document. getElementById ("bnt2"). value, 10 );
Var id3 = id1 + id2;
Document. getElementById ("bnt3"). value = id3;
}
</Script>
</Head>
<Body>
<Input type = "text" id = "bnt1"/> + <input type = "text" id = "bnt2"/> <input type = "button" value = "= "onclick =" sum () "/> <input type =" text "readonly =" readonly "id =" bnt3 "/>
</Body>
</Html>
I hope this article will help you design javascript programs.