求服务器端函数可以生成客户端JS代码并完成如下任务:
指定任意两个或三个textbox,在这两个或三个textbox中输入数字时,自动计算相乘的结果,并在另外的一个textbox中显示计算的值。当相乘几个textbox中有空着的时候,不显示计算值。
指定任意的n个textbox,自动计算其总和,显示在另外的一个textbox中。当前面几个textbox中的值改变时,自动更新总和。
界面如下所示:所有红框处,最后的textbox自动计算前面几个的乘积。所有蓝框的地方求和显示在最后一个textbox中。
注意:自动计算过程不能有postback。
在线等。当天有效。第一个能完美解决问题的300元通过网上银行转账付款。
页面代码如下:
<table rules="all" border="1" cellspacing="0" > <tr> <td colspan="6" align="center"><strong>外出人员费用</strong></td> </tr> <tr> <td>往返里程</td> <td align="right"><asp:TextBox ID="txtWangFanLiCheng" runat="server" Width="50px"></asp:TextBox>km </td> <td>人数</td> <td align="right"> <asp:TextBox ID="txtRenShu" runat="server" Width="50px"></asp:TextBox> 个</td> <td>天数</td> <td align="right"> <asp:TextBox ID="txtTianShu" runat="server" Width="50px"></asp:TextBox> 天</td> </tr> <tr> <td colspan="2">车船费</td> <td colspan="4" align="right"> <asp:TextBox ID="txtCheChuanFei" runat="server" Width="50px"></asp:TextBox> 元</td> </tr> <tr> <td colspan="2">食宿费</td> <td colspan="4" align="right"> <asp:TextBox ID="txtShiSuFei_Yuan" runat="server" Width="50px"></asp:TextBox> 元×<asp:TextBox ID="txtShiSuFei_Ren" runat="server" Width="50px"></asp:TextBox> 人× <asp:TextBox ID="txtShiSuFei_Tian" runat="server" Width="50px"></asp:TextBox> 天=<asp:TextBox ID="txtShiSuFei_Zong" runat="server" Width="50px"></asp:TextBox> 元</td> </tr> <tr> <td colspan="2">在途工时补助</td> <td colspan="4" align="right"> <asp:TextBox ID="txtZaiTuGongShiBuZhu_Yuan" runat="server" Width="50px"></asp:TextBox> 元×<asp:TextBox ID="txtZaiTuGongShiBuZhu_Ren" runat="server" Width="50px"></asp:TextBox> 人=<asp:TextBox ID="txtZaiTuGongShiBuZhu_Zong" runat="server" Width="50px"></asp:TextBox>元</td> </tr> <tr> <td colspan="6" align="center"><strong>外出服务用车费用</strong></td> </tr> <tr> <td colspan="2">第一次服务用车费</td> <td colspan="4" align="right"> <asp:TextBox ID="txtDiYiCiYongCheFei_Yuan" runat="server" Width="50px"></asp:TextBox> 元/Km× <asp:TextBox ID="txtDiYiCiYongCheFei_LiCheng" runat="server" Width="50px"></asp:TextBox> Km= <asp:TextBox ID="txtDiYiCiYongCheFei_Zong" runat="server" Width="50px"></asp:TextBox> 元</td> </tr> <tr> <td colspan="2">第二次服务用车费</td> <td colspan="4" align="right"> <asp:TextBox ID="txtDiErCiYongCheFei_Yuan" runat="server" Width="50px"></asp:TextBox> 元/Km× <asp:TextBox ID="txtDiErCiYongCheFei_LiCheng" runat="server" Width="50px"></asp:TextBox> Km=<asp:TextBox ID="txtDiErCiYongCheFei_Zong" runat="server" Width="50px"></asp:TextBox>元</td> </tr> <tr> <td colspan="6" align="center"><strong>修理工时费</strong></td> </tr> <tr> <td>工时数(h)</td> <td align="right"> <asp:TextBox ID="txtGongShiShu" runat="server" Width="50px"></asp:TextBox> 小时</td> <td>节假日上浮比例</td> <td align="right"> <asp:TextBox ID="txtJieJiaRiShangFuBiLi" runat="server" Width="50px"></asp:TextBox> %</td> <td>高寒上浮比例</td> <td align="right"> <asp:TextBox ID="txtGaoHanShangFuBiLi" runat="server" Width="50px"></asp:TextBox> %</td> </tr> <tr> <td>工时费</td> <td colspan="5" align="right">(基本工时)<asp:TextBox ID="txtGongShiFei_Yuan" runat="server" Width="50px"></asp:TextBox> 元×<asp:TextBox ID="txtGongShiFei_H" runat="server" Width="50px"></asp:TextBox>h×<asp:TextBox ID="txtGongShiFei_BiLi" runat="server" Width="50px"></asp:TextBox> %=<asp:TextBox ID="txtGongShiFei_Zong" runat="server" Width="50px"></asp:TextBox>元</td> </tr> <tr> <td>旧件运费</td> <td align="right"> <asp:TextBox ID="txtJiuJianYunFei" runat="server" Width="50px"></asp:TextBox> 元</td> <td colspan="2">其他费用</td> <td colspan="2" align="right"> <asp:TextBox ID="txtQiTaFeiYong" runat="server" Width="50px"></asp:TextBox> 元</td> </tr> <tr> <td>费用合计</td> <td colspan="5" align="right"> <asp:TextBox ID="txtFeiYongHeJi" runat="server" Width="50px"></asp:TextBox> 元</td> </tr></table>
4 回答
炎炎设计
TA贡献1808条经验 获得超4个赞
你可以在页面上放置一个隐藏域,后台根据需要放置要计算的表达式,然后每个输入框激发一个共同的事件,这个事件根据隐藏域的表达式(当然是要自己能够明白的表达式),查找各个需要计算的输入框的值,如果是乘法在计算的过程中遇到为空的输入框就立即返回false,如果是加法就取一个计算一个,空的就不计算,最后将总值赋值到要放置的文本框。
下面给出一个非常简单的demo:
---------------------
...
工时费
(基本工时)
元×
h×
%=
元
...
...
后台cs文件里面的部分:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//在后台这里你可以任意组织你的表达式
//表达式一|表达式二
//前台通过脚本截取=号前面的要赋值的文本框IDtxtGongShiFei_Zong=txtGongShiFei_Yuan*txtGongShiFei_H*txtGongShiFei_BiLi
this.hf1.Value = "txtGongShiFei_Yuan*txtGongShiFei_H*txtGongShiFei_BiLi";
}
}
添加回答
举报
0/150
提交
取消
