<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head lang="en"> <meta charset="UTF-8"> <title></title> <script> function add(){ var a=parseInt(document.getElementById("num1").value);/*获取a的值*/ var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a+b);/*value=a+b 将a+b的值传给num3*/ // alert(a+b); } function de(){ var a=parseInt(document.getElementById("num1").value)/*获取a的值*/ var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a-b); // alert(a-b); } function mul(){ /*放在方法里,点击才开始访问数据*/ var a=parseInt(document.getElementById("num1").value);/*获取a的值*/ var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a*b); //alert(a*b); } function chu(){ var a=parseInt(document.getElementById("num1").value);/*获取a的值*/ var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a/b); // alert(a/b); } </script> </head> <br> <label>简易计算器</label></br> <label>第一个数:</label><input type="=text" id="num1"></br> <label>第二个数:</label><input type="=text" id="num2"></br> <button onclick="add()">+</button> <button onclick="de()">-</button> <button onclick="mul()">*</button> <button onclick="chu()">/</button><br> <label>结果:</label><input type="text" id="num3"> </body> </html>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/html"><head lang="en"> <meta charset="UTF-8"> <title></title> <script> function add(){ var a=parseInt(document.getElementById("num1").value);/*获取a的值*/var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a+b);/*value=a+b 将a+b的值传给num3*/alert(a+b); } function de(){ var a=parseInt(document.getElementById("num1").value)/*获取a的值*/var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a-b); alert(a-b); } function mul(){ /*放在方法里,点击才开始访问数据*/var a=parseInt(document.getElementById("num1").value);/*获取a的值*/var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a*b); alert(a*b); } function chu(){ var a=parseInt(document.getElementById("num1").value);/*获取a的值*/var b=parseInt(document.getElementById("num2").value); var c=parseInt(document.getElementById("num3").value=a/b); alert(a/b); } </script></head><br> <label>简易计算器</label></br> <label>第一个数:</label><input type="=text" id="num1"></br> <label>第二个数:</label><input type="=text" id="num2"></br> <button onclick="add()">+</button> <button onclick="de()">-</button> <button onclick="mul()">*</button> <button onclick="chu()">/</button><br> <label>结果:</label><input type="text" id="num3"></body></html>
时间: 2024-10-13 00:14:14