粘贴在一个html文件中运行查
<!DOCTYPE html> <html> <head> <title>js运算符</title> </head> <body> <h2>1:加法</h2> <p id='1'></p> <button type='button' onclick="func1()">返回 1 + 2 的值</button> <script> function func1(){ let num_1 = 1; let num_2 = 2; let num_3 = num_1 + num_2; document.getElementById('1').innerHTML = num_3; } </script> <h2>2:减法</h2> <p id='2'></p> <button type='button' onclick="func2()">返回 2 - 1 的值</button> <script> function func2(){ let num_1 = 1; let num_2 = 2; let num_3 = num_2 - num_1; document.getElementById('2').innerHTML = num_3; } </script> <h2>3:乘法</h2> <p id='3'></p> <button type='button' onclick="func3()">返回 2 * 1 的值</button> <script> function func3(){ let num_1 = 2; let num_2 = 2; let num_3 = num_2 * num_1; document.getElementById('3').innerHTML = num_3; } </script> <h2>4:除法</h2> <p id='4'></p> <button type='button' onclick="func4()">返回 6 / 2 的值</button> <script> function func4(){ let num_1 = 2; let num_2 = 6; let num_3 = num_2 / num_1; document.getElementById('4').innerHTML = num_3; } </script> <h2>5:取模(余数)</h2> <p id='5'></p> <button type='button' onclick="func5()">返回 6 / 4 的余数</button> <script> function func5(){ let num_1 = 4; let num_2 = 6; let num_3 = num_2 % num_1; document.getElementById('5').innerHTML = num_3; } </script> <h2>6:递加</h2> <p id='6'></p> <button type='button' onclick="func6()">4++ 值为5</button> <script> function func6(){ let num_1 = 4; num_1 ++; document.getElementById('6').innerHTML = num_1; } </script> <h2>7:递减</h2> <p id='7'></p> <button type='button' onclick="func7()">4-- 值为3</button> <script> function func7(){ let num_1 = 4; num_1 --; document.getElementById('7').innerHTML = num_1; } </script> <h2>8:幂(乘方)</h2> <p id='8'></p> <button type='button' onclick="func8()">4的2次乘方 值为16</button> <script> function func8(){ var num_1 = 4; document.getElementById('8').innerHTML = Math.pow(2,2); } </script> <h2>7:相关</h2> <h3> = += -= *= /= %= </h3> </body> </html>