JS simple calculator instance
This article mainly introduces the implementation method of the simple calculator of JS, and analyzes the tips for implementing the computing function of js by using addition instances. For more information, see
This article describes how to implement a simple JavaScript calculator. Share it with you for your reference. The specific implementation method is as follows:
The 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.