第十六节 JavaScript分之语句之算数运算符

 1 <!DOCTYPE html>
 2 <!-- % 求余 0%任何数=0
 3      a++ 等同于a += 1
 4       -->
 5 <html lang="en">
 6 <head>
 7     <meta charset="UTF-8">
 8     <title>Document</title>
 9     <script type="text/javascript">
10         window.onload = function(){
11             var oInput01 = document.getElementById('input01');
12             var oInput02 = document.getElementById('input02');
13             var oBtn = document.getElementById('btn');
14             oBtn.onclick = function(){
15                 var iVal01 = parseInt(oInput01.value);  // 将输入的字符串转换成int类型
16                 var iVal02 = parseInt(oInput02.value);
17                 alert(iVal01 % iVal02);
18 
19             }
20         }
21     </script>
22 </head>
23 <body>
24     <input type="text" name="" id="input01">+
25     <input type="text" name="" id="input02">
26     <input type="button" name="" id="btn" value="求余">
27 </body>
28 </html>

 

posted @ 2020-03-14 16:56  kog_maw  阅读(93)  评论(0编辑  收藏  举报