码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript加法器

时间:2018-10-14 20:55:52      阅读:604      评论:0      收藏:0      [点我收藏+]

标签:body   input   index   sub   function   color   加法   title   res   

 1 <html>
 2     <head>
 3         <title>
 4             加法器
 5         </title>
 6         <meta charset="UTF-8">
 7         <style type="text/css">
 8     
 9         </style>
10         
11         <script type="text/javascript">
12         function jFq()
13         {
14             var shuru = document.getElementById("shuru").value;                //获取id
15             var jieguo = document.getElementById("jieguo");             //获取id
16             var result = 0;
17             while(shuru.indexOf("+") != -1)
18             {
19                 var z = shuru.indexOf("+");
20                 result = shuru.substring(0,z)*1;
21                 shuru = shuru.substring(z+1,shuru.length);
22             }
23             result = (shuru)*1 + result;
24             jieguo.value = result;
25         }
26         </script>
27     </head>
28 <body>
29     <div>
30     <form>
31     <input id="shuru" type="text" />
32     <input type="button" value="计算" onclick="jFq()" /><br />
33     输出结果:<br />
34     <input id="jieguo" type="text" />
35     </form>
36     </div>
37 </body>
38 </html>

 

JavaScript加法器

标签:body   input   index   sub   function   color   加法   title   res   

原文地址:https://www.cnblogs.com/cxwl/p/9787312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!