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 ...
随机推荐
- 几个好用的截取字符串的php函数分享
分享几个好用的PHP 截取字符串函数(支持gb2312和utf-8). 1.截取GB2312字符用的函数 <?php /** **截取中文字符串 * edit by www.jbxue.com ...
- Demo学习: Collapsible Panels
Collapsible Panels 设置TUniPanel布局属性,布局属性在Ext里是比较常用的属性,当前版本虽已经提供了布局功能,但很不完善,比如当Panel.TitlePosition=tpR ...
- java 中的this关键字的几种用法
转自:http://blog.csdn.net/anmei2010/article/details/4091227 1. 当成员变量和局部变量重名时,在方法中使用this时,表示的是该方法所在 ...
- html lang
目前,语言的标签表示法的国际标准是RFC 4646,名称是<Tags for Identifying Languages>.简单说,这个文件规定,一种语言的标签应该按照如下方式排列: la ...
- 1067. Sort with Swap(0,*) (25)
时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given any permutation of the num ...
- fedora gnome extension
如果想在gnome-shell桌面放点个性化的应用,可以在https://extensions.gnome.org网站上安装扩展(记得使用firefox). 下面我记录几个我们觉得还不错的扩展: 1. ...
- SSL与TLS的区别以及介绍
转载 :http://kb.cnblogs.com/page/197396/ SSL:(Secure Socket Layer,安全套接字层),位于可靠的面向连接的网络层协议和应用层协议之间的一种协议 ...
- zepto点击事件兼容pc和mobile
判断pc还是mobile,重写click事件 var CLICK='click'; (function browserRedirect() { var sUserAgent = navigator.u ...
- <span> <div> 局部 keydown ,keyup事件。页面部分div $(document) 无效,可能焦点,添加焦点。
前天改一个bug, js 实现的一个 面板拖拉,左右各两个列表,中间面板画线连接,页面左侧列表选中后,key 事件无效.右侧选中确有效,很奇怪,查看源码,左侧选中后,$(document).on(&q ...
- Android 如何切换到 Transform API?
摘要: 如果你的 Android 构建中涉及到字节码插装(bytecode instrumentation),或者应用中提供了进行插装的插件,并希望它能支持 Instant Run,那么你必须切换到 ...