This article describes the implementation method of JS simple calculator. Share it for your reference. The specific implementation method is as follows:
The code copy 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 of value into 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 be helpful to everyone's JavaScript programming.