日期:2013-03-18  浏览次数:21283 次

cart.js

请存为cart.js,并且和前部分html放在同一个目录中

//------------------------------------------------------------------------------
//
// file name : cart.js
//
// description: 购物车前台用javascript 函数库
//
// function list : On_Cancel(txtAmount , txtSum)---- 取消该项
// On_Update() ---- 更新数量
// On_Del() ---- 全部删除
// UpdateDate() ---- 更新表单显示
// Round() ---- 四舍五入取指定小数位数
//
// Aurthor: LiuYunpeng
//
// Date: 2000/09/03
//
// History: 2000/09/03 version 1.0
//
//------------------------------------------------------------------------------


//----------------code begin here------------------------------------------

function On_Cancel(txtAmount , txtSum)
{
txtAmount.value = 0 ;
txtSum.value = 0 ;
UpdateData();
}

//更新表单显示
function UpdateData()
{
var m_aAmount = new Array() ;
var m_aPrice = new Array() ;
var m_aDiscount = new Array() ;
var m_aSum = new Array() ;
var m_numTotal = 0 ;
var i , j , k , m;
i = 0 ;
j = 0 ;
k = 0 ;
m = 0 ;

//求数量
for (i = 0 ; i < document.frmOrder .elements .length ; i ++ )
{
if (frmOrder.elements [i].name.substring(0 , 9) == "txtAmount")
{
m_aAmount[j] = frmOrder.elements [i].value ;
j ++ ;
}
if (frmOrder.elements [i].name.substring(0 , 14) == "txtTicketPrice")
{

m_aPrice[k] = Round(frmOrder.elements[i].value , 2) ;
k ++ ;
}
if (frmOrder.elements [i].name.substring(0 , 14) == "hidTicketDisco")
{
m_aDiscount[m] = frmOrder.elements[i].value ;
m ++ ;
}
}

for ( i = 0 ; i < k ; i ++)
{
m_aSum[i] = Round(m_aPrice[i] * m_aAmount[i] * m_aDiscount[i] / 100 , 2);

}


//更新form
j = 0 ;
for (i = 0 ; i < document.frmOrder .elements .length ; i ++ )
{
if (frmOrder.elements [i].name.substring(0 , 6) == "txtSum")
{
frmOrder.elements [i].value = m_aSum[j] ;
m_numTotal = Round(m_numTotal + m_aSum[j] , 2);
j ++ ;
}

}

document.frmOrder .txtTotal .value = m_numTotal ;

return 0;
}

//更新数量
function On_Update()
{

if (document.frmOrder .btnUpdate .value == "修改数量")
{
document.frmOrder .btnUpdate .value = "更新数量"
for (var i=0 ; i < frmOrder.elements.length ; i++)
{
if (frmOrder.elements [i].name.substring(0 , 9) == "txtAmount")
{

frmOrder.elements [i].disabled = false ;
frmOrder.elements[i].style.borderStyle = "ridge ";
document.frmOrder .btnBuy .disabled = true ;
document.frmOrder .btnCancel .disabled = true ;
document.frmOrder .btnContinue .disabled = true ;
document.frmOrder .btnDel .disabled =true ;
}

}