1 <html>
2 <head>
3 <script language="javascript">
4 function getValue(){
5 var numberA = document.getElementById("numberA");
6 var numberB = document.getElementById("numberB");
7 var result = document.getElementById("result");
8
9 if(numberA.value=="" || numberB.value=="")return;
10 result.value = parseInt(numberA.value)+parseInt(numberB.value);
11 }
12 </script>
13 </head>
14 <body>
15 <form>
16 <h2 align="center">通过JavaScript动态输入计算</h2>
17 <input type="text" id="numberA" onkeyup="javascript:getValue()" /> +
18 <input type="text" id="numberB" onkeyup="javascript:getValue()" /> =
19 <input type="text" id="result" />
20 </form>
21 </body>
22 </html>
2 <head>
3 <script language="javascript">
4 function getValue(){
5 var numberA = document.getElementById("numberA");
6 var numberB = document.getElementById("numberB");
7 var result = document.getElementById("result");
8
9 if(numberA.value=="" || numberB.value=="")return;
10 result.value = parseInt(numberA.value)+parseInt(numberB.value);
11 }
12 </script>
13 </head>
14 <body>
15 <form>
16 <h2 align="center">通过JavaScript动态输入计算</h2>
17 <input type="text" id="numberA" onkeyup="javascript:getValue()" /> +
18 <input type="text" id="numberB" onkeyup="javascript:getValue()" /> =
19 <input type="text" id="result" />
20 </form>
21 </body>
22 </html>