主函数: <html> <head> <title>加减乘除title> <script type="text/javascript"> //java计算函数 function fun() { var fa = parseInt(document.getElementById('fa').value); var fb = parseInt(document.getElementById('fb').value); var t = parseInt(document.getElementById('DropDownList1').value); var fc = document.getElementById('fc'); if(isNaN(fa) || isNaN(fb)){ alert("输入错误,请重新输入"); return; } switch(t){ case 1: fc.value = fa + fb; break; case 2: fc.value = fa - fb; break; case 3: fc.value = fa * fb; break; case 4: fc.value = fa / fb; break; } } script> head> <body> <form id="form1" runat="server"> <input type="text" id="fa" value=""/> <%-- 选项菜单选择--%> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Value="1">+asp:ListItem> <asp:ListItem Value="2">-asp:ListItem> <asp:ListItem Value="3">*asp:ListItem> <asp:ListItem Value="4">/asp:ListItem> asp:DropDownList> <input type="text" id="fb" value=""/> <input id="Button1" type="button" value="=" onclick="fun()" /> <input type="text" id="fc" value=""/> form> body> html> 只要将此函数运行即可出来一个简单的计算器 实现加减乘除功能 本文来源:https://www.wddqw.com/doc/ef6ccc80d0d233d4b04e6905.html