相关代码,设计一个程序,计算后在网页上输出结果
3条回答 默认 最新
CSDN专家-showbo 2022-01-01 15:42关注计算器?这种直接前端js就能实现,不需要经过服务器,参考:https://c.runoob.com/codedemo/3654/
一定要C#,webform简单示例如下
x.aspx
<%@ Page Language="C#" AutoEventWireup="true"%> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { if (a.Text != "" && b.Text != "" && opr.Text != "") { double da = 0, db = 0, dc = 0; double.TryParse(a.Text, out da); double.TryParse(b.Text, out db); switch (opr.Text) { case "+": dc = da + db; break; case "-": dc = da - db; break; case "*": dc = da * db; break; case "/": dc = da / db; break; } c.Text = Math.Round(dc, 2).ToString(); } else c.Text = ""; } } </script> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Asp.Net计算器</title> </head> <body> <form id="form1" runat="server"> <asp:TextBox runat="server" ID="a"></asp:TextBox> <asp:DropDownList ID="opr" runat="server" AutoPostBack="true"> <asp:ListItem Value="">请选择操作</asp:ListItem> <asp:ListItem Value="+">+</asp:ListItem> <asp:ListItem Value="-">-</asp:ListItem> <asp:ListItem Value="*">*</asp:ListItem> <asp:ListItem Value="/">/</asp:ListItem> </asp:DropDownList> <asp:TextBox runat="server" ID="b"></asp:TextBox> = <asp:TextBox runat="server" ID="c"></asp:TextBox> </form> </body> </html>
有其他问题可以继续交流~本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录