js 动态计算折扣后总价格
<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">
原价(¥) <span id="spanoldprice" style="color: Red; font-size: x-large"><%=ViewData["totalPrice"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
折扣(%) <span id="spandistinct" style="color: Red; font-size: x-large"><%=ViewData["discount"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
总价(¥) <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 动态计算折扣后总价格的更多相关文章
- JS动态生成表格后 合并单元格
JS动态生成表格后 合并单元格 最近做项目碰到表格中的单元格合并的问题,需求是这样的,首先发ajax请求 请求回来后的数据 动态生成表格数据,但是生成后如果编号或者(根据其他的内容)有相同时,要合并单 ...
- 还能输入多少字?(JS动态计算)
<div class="m-form ovh"> <div class="hd"> <span class="fr&qu ...
- 理解rem实现响应式布局原理及js动态计算rem
前言 移动端布局中,童鞋们会使用到rem作为css单位进行不同手机屏幕大小上的适配.那么来讲讲rem在其中起的作用和如何动态设置rem的值. 1.什么是rem rem是相对于根元素(html标签)的字 ...
- js动态获取地址栏后的参数
原文链接:https://blog.csdn.net/qq_37936542/article/details/78866651 需求:js动态的获取地址栏后面的参数 js代码: alert(GetQu ...
- 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 ...
- JS动态计算移动端rem的解决方案
首先介绍下rem 说起rem就的说px,em: PX为单位 在Web页面初期制作中,我们都是使用“px”来设置我们的文本,因为他比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的 ...
- js动态计算移动端rem
在做移动端web app的时候,众所周知,移动设备分辨率五花八门,虽然我们可以通过CSS3的media query来实现适配,例如下面这样: html { font-size : 20px; } @m ...
- JS动态插入HTML后不能执行后续JQUERY操作
通过js追加的html 发现 不能点击 执行函数 普通绑定事件:$('.btn1').click(function(){}绑定 事件委托 解决方法: $("body").d ...
- 关于cefsharp 获取js动态加载后的信息
IFrame frame = null; var identifiers = Browser.GetBrowser().GetFrameIdentifiers(); foreach (var i in ...
随机推荐
- 概念:RPG与RPGLE的区别
RPG是OPM编程模式,即RPG编程的代码不能编译成*MODULE:编译只能直接生成一个程序,*PGM. RPGLE是ILE编程模式.OS/400环境下,ILE是集成开发环境.在ILE环境下,所 ...
- javascript insertBefore 和 appendChild
js的appendChild()方法 :在一个元素内部追加一个子节点. js的insertBefore()方法:在一个元素内部指定的子节点之前插入子节点. 很明显,appendChild()方法只需要 ...
- iOS开发进阶 - 使用shell脚本自动打包上传到fir.im上-b
用fir.im测试已经好长时间了,感觉每次打包上传都很麻烦,想着是不是可以用脚本自动打包,在网上搜了一下确实有,下面总结一下如何使用脚本自动打包上传到fir.im,以及打包过程中遇到的问题和解决办法 ...
- 自己利用jQuery实现的win8图标浮动更新
在学校参加网页设计大赛时,由于美工设计的刚好是metro风格的(其实她们从来没有用过win8也没有了解过),而本人也很喜欢win8的界面,于是就做了一个metro风格的作品.虽然最终没能获奖,但是觉得 ...
- win7 提升windows服务权限使非管理员用户可以控制windows服务的开启和关闭
#include <windows.h>#include <tchar.h>#include <strsafe.h>#include <aclapi.h> ...
- 1044: [HAOI2008]木棍分割 - BZOJ
Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长 ...
- 动态内存 this指针
#include <iostream> #include <string> class Company { public: Company(std::string theNam ...
- [转载]VS2012创建MVC3项目提示错误: 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。
如果在没有安装vs2012 update3升级包的情况下,创建MVC3项目会出现下面的错误信息. 因为VS2012已经全面切换到使用NuGet这个第三方开源工具来管理项目包和引用模块了,使用VS201 ...
- 汇编Ring 3下实现 HOOK API
[文章标题]汇编ring3下实现HOOK API [文章作者]nohacks(非安全,hacker0058) [作者主页]hacker0058.ys168.com [文章出处]看雪论坛(bbs.ped ...
- linux cd命令不带路径参数
#切换到当前用户的主目录.若为root用户,则切换到/root,若普通用户,则切换到/home/username $ cd