<a title="减一" onclick="subtractCount('p001')" href="#none" clstag="clickcart|keycount|shoppingcartpop|diminish1"><img src="skin/images/bag_close.gif" alt="66" border="none" width="20"/></a>
<input id="p001Count" width="20" value="1" maxlength="4" type="text" name="txtChange593235" onkeyup="keyUpCheck(this,'p001')" />
<a title="加一" onclick="addCount('p001')" href="#none" clstag="clickcart|keycount|shoppingcartpop|add1"><img src="skin/images/bag_open.gif" alt="666" border="none" width="20"/></a>
<input type="hidden" id="p001PerPrice" value="3400.31"/>
<input type="hidden" id="p001StockCount" value="10"/>
</td>
</tr>
<tr>
<td width="7%">商品编号</td>
<!--td width='6%' style='height:30px;'>商品编号</td-->
<td>商品名称</td>
<td width="14%">京东价</td>
<td width="8%">返现</td>
<td width="8%">赠送积分</td>
<!--td width='10%'>京东价</td> <td width='10%'>优惠明细</td> <td width='11%'>送至{Provinces}</td-->
<td width="9%">商品数量</td>
<td width="7%">删除商品</td>
</tr>
<tr>
<td>593235</td>
<td><div><a target="_blank" clstag="clickcart|keycount|shoppingcartpop|p-imglistcart"><img alt="66" /></a></div>
</td>
<td>¥10.3 </td>
<td>¥0.00</td>
<td>0</td>
<!--td>-</td-->
<!--td></td-->
<td>
<a title="减一" onclick="subtractCount('p002')" href="#none" clstag="clickcart|keycount|shoppingcartpop|diminish1"><img src="skin/images/bag_close.gif" alt="66" border="none" width="20"/></a>
<input id="p002Count" width="20" value="1" maxlength="4" type="text" name="txtChange593235" onkeyup="keyUpCheck(this,'p002')" />
<a title="加一" onclick="addCount('p002')" href="#none" clstag="clickcart|keycount|shoppingcartpop|add1"><img src="skin/images/bag_open.gif" alt="666" border="none" width="20"/></a>
<input type="hidden" id="p002PerPrice" value="1000.3"/>
<input type="hidden" id="p002StockCount" value="10"/>
</td>
</tr>
<tr>
<td colspan="7"><br />
<strong>商品总金额:¥<span id="cartBottom_price">3499.00</span>元</strong></td>
</tr>
</table>
<script type="text/javascript">
/*
要点元素
<a title="减一" onclick="subtractCount('p001')" --传产品编号唯一
<a title="加一" onclick="addCount('p002')" --上同功能加
//产品数量 id="pid"+"Count"
onkeyup="keyUpCheck(this,'p002')" 这个是检查库存数量的
<input id="p002Count" width="20" value="1" maxlength="4" type="text" name="txtChange593235" onkeyup="keyUpCheck(this,'p002')" />
以下是产品单价的隐藏域
<input type="hidden" id="p002PerPrice" value="1000.3"/>
一下产品库存数量的隐藏域
<input type="hidden" id="p002StockCount" value="10"/>
这个地方是要计算产品的id集合
var pids = ["p001","p002"];
cartBottom_price 总价格id
PerCount
*/
var pids = ["p001","p002"];
function JSRound(fNum,fBit){
var i = 1;
var m = 1;
var tempNum = fNum;
for(i=0;i <= fBit;i++)
m = m * 10;
tempNum = tempNum * m;
tempNum = Math.round(tempNum);
tempNum = tempNum / m;
return tempNum;
}
function $(id)
{
return document.getElementById(id);
}
function addCount(pid)
{
var currentVal = $(pid+"Count").value;
var stockCurrentVal = $(pid+'StockCount').value;
currentVal=parseInt(currentVal)+1;
if(currentVal>stockCurrentVal)
{
alert("库存为"+stockCurrentVal+"个仅能购买次数量");
currentVal=stockCurrentVal;
}
$(pid+"Count").value=currentVal;
computeTotal();
}
function subtractCount(pid)
{
var currentVal = $(pid+"Count").value;
var stockCurrentVal = $(pid+'StockCount').value;
currentVal=parseInt(currentVal)-1;
if(currentVal<=0)
{
currentVal=1;
}
if(currentVal>stockCurrentVal)
{
alert("库存为"+stockCurrentVal+"个仅能购买次数量");
currentVal=stockCurrentVal;
}
$(pid+"Count").value=currentVal;
computeTotal();
}
function computeTotal(){
var totalMoney =0;
var perMoney=0;
for(var i=0;i<pids.length;i++)
{
try{
perMoney = parseFloat($(pids[i]+"PerPrice").value)*parseInt($(pids[i]+"Count").value);
}
catch(e)
{
perMoney=0;
}
totalMoney+=perMoney;
}
totalMoney = JSRound(totalMoney,2);
$("cartBottom_price").innerHTML=totalMoney;
}
function keyUpCheck(obj,pid){
obj.value = obj.value.replace(/[\D]+/,'');
var stockCurrentVal = $(pid+'StockCount').value;
if(parseInt(obj.value)>stockCurrentVal)
{
obj.value=stockCurrentVal;
}
}
</script>
posted on 2012-04-01 13:15
王豪 阅读(648)
评论(0) 编辑 收藏