Home > Web Front-end > JS Tutorial > JS operation numerical calculation in input tag

JS operation numerical calculation in input tag

php中世界最好的语言
Release: 2018-04-19 10:21:17
Original
2483 people have browsed it

This time I bring to you, what are the precautions, the following is a practical case, let's take a look.

<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title></title>
<script>
window.onload=function(){
var oIput1=document.getElementById(&#39;put1&#39;);
var oIput2=document.getElementById(&#39;put2&#39;);
var nAdd=document.getElementById(&#39;add&#39;);
var nSub=document.getElementById(&#39;subtraction&#39;);
nAdd.onclick=function(){
var a=Number(oIput1.value);
var b=Number(oIput2.value);
c = a+b;
alert(c);
}
nSub.onclick=function(){
var a=Number(oIput1.value);
var b=Number(oIput2.value);
c = a-b;
alert(c);
}
}
</script>
</head>
<body>
数值1:<inputid="put1"type="text"value=""/>
数值2:<inputid="put2"type="text"value=""/>
<inputtype="button"id="add"value="求和"/>
<inputtype="button"id="subtraction"value="相减"/>
</body>
</html>
Copy after login


# I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Real-time acquisition of input input box content

Detailed explanation of the use of Vue scope slots

vue implements the function of clicking on the image to enlarge (with code)

The above is the detailed content of JS operation numerical calculation in input tag. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template