标签: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>
标签:body input index sub function color 加法 title res
原文地址:https://www.cnblogs.com/cxwl/p/9787312.html