<script type="text/javascript">

<!---计算折扣后的总价格--->
function outtotalprice(i) {
document.getElementsByName("items[#index#].TotaPricel")[i].value = document.getElementsByName("items[#index#].qty")[i].value * document.getElementsByName("items[#index#].Price")[i].value; }
<!----在动态显示 原价、折扣、折扣后的总价---->
function OutTotalPrice() {
var len = document.getElementsByName("items[#index#].TotaPricel").length;
var ordertotalprice = ;
for (var j = ; j < len; j++) {
ordertotalprice += parseFloat(document.getElementsByName("items[#index#].TotaPricel")[j].value);
}
document.getElementById("Out.TotalPrice").value = ordertotalprice.toFixed();
var strdiscount = parseFloat(parseInt(document.getElementById("Out.discount").value) / ).toFixed();
var strdiscountPrice = parseFloat(ordertotalprice * strdiscount).toFixed();
document.getElementById("Out.discountPrice").value = strdiscountPrice;
document.getElementById("spanoldprice").innerHTML = ordertotalprice.toFixed();
document.getElementById("spandistinct").innerHTML = document.getElementById("Out.discount").value;
document.getElementById("spandisprice").innerHTML = strdiscountPrice;
}
</script>

声明两个对象:

  <%: Html.HiddenFor(model => model.TotalPrice, new { id = "Out.TotalPrice" })%>
<%: Html.HiddenFor(model => model.discountPrice, new { id = "Out.discountPrice" })%>
   <div class="sortDrag" style="width: 20%; border: 1px solid #e66; margin: 5px; float: inherit;min-height: 220px;">
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
原价(¥)&nbsp;&nbsp;&nbsp;<span id="spanoldprice" style="color: Red; font-size: x-large"><%=ViewData["totalPrice"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
折扣(%)&nbsp;&nbsp;&nbsp;<span id="spandistinct" style="color: Red; font-size: x-large"><%=ViewData["discount"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
总价(¥)&nbsp;&nbsp;&nbsp;<span id="spandisprice" style="color: Red; font-size: x-large"><%=ViewData["discountPrice"]%></span></div>
</div>

后台代码

 private string BindTableOutSend(IList<VOutProceManager> objList)
{
sbProcessingtype = null;
getProcessingtype();
string strCalMethod = "";
StringBuilder sb = new StringBuilder();
int i = ;
string currentdate = DateTime.Now.ToString("yyyy-MM-dd");
foreach (VOutProceManager obj in objList)
{
if (ViewBag.outauditstate <= )
{
sb.Append("<tr class=\"unitBox\">");
sb.Append("<input type=\"hidden\" name=\"items[#index#].Id\" submitName=\"items[" + i + "].Id\" value=\"" + obj.Id + "\" /> ");
sb.Append("<input type=\"hidden\" name=\"items[#index#].bomID\" submitName=\"items[" + i + "].bomID\" value=\"" + obj.bomID + "\" /> ");
sb.Append("<input type=\"hidden\" name=\"items[#index#].Isbom\" submitName=\"items[" + i + "].Isbom\" value=\"" + obj.Isbom + "\" /> ");
sb.Append("<td ><input class=\"textInput \" size='15' readonly=\"readonly\" value=\"" + obj.mouldNo + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" value=\"" + obj.partName + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='3' readonly=\"readonly\" value=\"" + obj.drawingNo + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" name=\"items[#index#].qty\" submitName=\"items[" + i + "].qty\" value=\"" + obj.qty + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='15' readonly=\"readonly\" name=\"items[#index#].typeName\" submitName=\"items[" + i + "].typeName\" value=\"" + obj.typeName + "\" > </td> ");
sb.Append("<td>");
sb.Append("<SELECT name=\"items[#index#].PriceType\" submitName=\"items[" + i + "].PriceType\">");
strCalMethod = obj.PriceType;
if (strCalMethod == "体积")
{
sb.Append("<OPTION selected value='体积'>体积</OPTION><OPTION value=面积>面积</OPTION>");
}
else
{
sb.Append("<OPTION value='体积'>体积</OPTION><OPTION selected value=面积>面积</OPTION>");
}
sb.Append("</SELECT>");
sb.Append("</td>");
sb.Append("<td ><input class=\"textInput required number\" size='9' name=\"items[#index#].Quantity\" submitName=\"items[" + i + "].Quantity\" value=\"" + obj.Quantity + "\" > </td>");
sb.Append("<td ><input class=\"textInput\" type=\"lookup\" size='3' name=\"items[#index#].Unit.Name\" lookupgroup=\"items[#index#].Unit\" suggesturl=\"projectGL/Mould/GetName?typeid=7\" suggestfields=\"Name\" postfield=\"keywords\" submitName=\"items[" + i + "].Unit.Unit\" value=\"" + obj.Unit + "\" > </td>");
sb.Append("<td ><input class=\"textInput required number\" size='9' name=\"items[#index#].Price\" onkeyup=\"outtotalprice(" + i + ");OutTotalPrice()\" submitName=\"items[" + i + "].Price\" value=\"" + obj.Price + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" name=\"items[#index#].TotaPricel\" submitName=\"items[" + i + "].TotaPricel\" value=\"" + obj.TotaPricel + "\" > </td>");
sb.Append("</tr>");
i++;
}
}
return sb.ToString();
}

首次加载:初始化的后台显示(未输入价格前)

   ViewData["totalPrice"] = ;
ViewData["discount"] = "100%";
ViewData["discountPrice"] = ;

在提交的方法里

判断是否输入单价:把每种类型的总价累加起来,得到最后的总价:

decimal totalprice = 0.0m;
decimal countprice = 0.0m;
bool iszero = true;
while (!string.IsNullOrEmpty(Request.Form["items[" + i + "].Id"]))
{ totalprice = decimal.Parse(Request.Form["items[" + i + "].TotaPricel"]);
countprice += totalprice;
ViewData["totalPrice"] = countprice;
if (totalprice <= )
{
iszero = false;
break;
}
i++;
}
if (!iszero)
{
return SaveSuccessStr("", "单价不能小于等于0!", "", "", "");
}

在提交的方法里计算折扣后的总价格:

  if (Tmodels.discount == )
Tmodels.discountPrice = countprice;
else
Tmodels.discountPrice = Convert.ToDecimal(countprice * (Tmodels.discount / 100.0m));

js 动态计算折扣后总价格的更多相关文章

  1. JS动态生成表格后 合并单元格

    JS动态生成表格后 合并单元格 最近做项目碰到表格中的单元格合并的问题,需求是这样的,首先发ajax请求 请求回来后的数据 动态生成表格数据,但是生成后如果编号或者(根据其他的内容)有相同时,要合并单 ...

  2. 还能输入多少字?(JS动态计算)

    <div class="m-form ovh"> <div class="hd"> <span class="fr&qu ...

  3. 理解rem实现响应式布局原理及js动态计算rem

    前言 移动端布局中,童鞋们会使用到rem作为css单位进行不同手机屏幕大小上的适配.那么来讲讲rem在其中起的作用和如何动态设置rem的值. 1.什么是rem rem是相对于根元素(html标签)的字 ...

  4. js动态获取地址栏后的参数

    原文链接:https://blog.csdn.net/qq_37936542/article/details/78866651 需求:js动态的获取地址栏后面的参数 js代码: alert(GetQu ...

  5. js动态计算移动端rem适配问题

    第一:css3的media query来实现适配,例如下面这样: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 ...

  6. JS动态计算移动端rem的解决方案

    首先介绍下rem 说起rem就的说px,em: PX为单位 在Web页面初期制作中,我们都是使用“px”来设置我们的文本,因为他比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的 ...

  7. js动态计算移动端rem

    在做移动端web app的时候,众所周知,移动设备分辨率五花八门,虽然我们可以通过CSS3的media query来实现适配,例如下面这样: html { font-size : 20px; } @m ...

  8. JS动态插入HTML后不能执行后续JQUERY操作

    通过js追加的html 发现 不能点击 执行函数   普通绑定事件:$('.btn1').click(function(){}绑定 事件委托   解决方法: $("body").d ...

  9. 关于cefsharp 获取js动态加载后的信息

    IFrame frame = null; var identifiers = Browser.GetBrowser().GetFrameIdentifiers(); foreach (var i in ...

随机推荐

  1. Huawei HG556a A版 刷 openwrt

    一直想玩玩openwrt,调研了一下 HG556a尽管散热很烂,但性价比超高,于是淘宝入手一台A版,A版和C版区别为wifi芯片: 到货后在网上找了几个教程便开始动手刷openwrt,但刷机的过程中还 ...

  2. easy ui 表单ajax和from两种提交数据方法

    说明: ①ajax在表单提交时需要将所有表单的控件的数据一一获取并赋值传到后台 ②form在提交时,只要给控件加name属性,在提交时就可以将表单数据提交到后台,不需要一一获取再进行赋值. ajax ...

  3. SVN备份教程(一)

    最近一段时间在项目中用到了SVN备份的相关内容,这里给大家做一个简单的教程,重点在于SVN备份环境的搭建过程中,大家学到的解决问题的思维方式. 1.分类 SVN备份主要分为两种:一种是远程备份,另一种 ...

  4. C语言关键字-volatile

    1.C语言关键字volatile     C 语言关键字volatile(注意它是用来修饰变量而不是上面介绍的__volatile__)表明某个变量的值可能在外部被改变,因此对这些变量的存取 不能缓存 ...

  5. Fail-fast的原因及解决方法

    [转载]:http://blog.csdn.net/chenssy/article/details/38151189 在JDK的Collection中我们时常会看到类似于这样的话: 例如,ArrayL ...

  6. 1038: [ZJOI2008]瞭望塔 - BZOJ

    Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...

  7. CSS样式表引用方式

    最近讲课中,有些学员对调用样式表老是有含糊不清?大体说来有四种方式: 1.外部文件引用方式;(推荐使用) 2.使用@import引用外部CSS文件; 3.内部文档头方式也叫内嵌法调用; 4.直接插入式 ...

  8. 有关js的变量、作用域和内存问题

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(四) js共有5种基本数据类型:Undefined.NULL.Boolean.Numbe ...

  9. Monad学习

    这是观看Cousera上的课程<Principles of Reactive Programming>中week1里的Monad一节所做的笔记. What is a Monad? What ...

  10. ***phpredis扩展安装总结

    phpredis扩展安装总结:PHP扩展安装在[root@iZ254lfyd6nZ lampp]# cd include 目录下创建一个目录phpredis下载扩展:wget https://gith ...