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>