gilgamesh-hjb

知识点:

1.从input中取值:

  var a=parseInt(document.getElementById(\'num1\').value);

2.把数值放回input中

  document.getElementById(\'result\').value=a+b;

 1 <html>
 2 
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 5     <style>
 6         input{
 7   width:50px;
 8 }
 9 </style>
10     <script type="text/javascript">
11     function calc() {
12         // body...
13         var a = parseInt(document.getElementById(\'num1\').value);
14         var b = parseInt(document.getElementById(\'num2\').value);
15         document.getElementById(\'result\').value = a + b;
16     }
17     </script>
18 </head>
19 
20 <body><input type="text" id="num1"> +
21     <input type="text" id="num2">
22     =
23     <input type="text" id="result">
24     <input type="button" value="计算" onclick="calc()"></body>
25 
26 </html>

效果图:

 

分类:

技术点:

相关文章: