<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>