This article mainly introduces the implementation of JS simple calculator, with the addition of an example analysis of JS implementation of the calculation function of the skills, the need for friends can refer to the
This paper illustrates the implementation of JS simple calculator. Share to everyone for your reference. The implementation methods are as follows:
The code is as follows:
<title></title>
<script type= "Text/javascript" >
function sum () {
JS type conversion parseint (value,10) means to convert value to decimal values
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>
<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>
I hope this article will help you with your JavaScript programming.