本篇文章主要介绍了"asp+ajax版的购物车",主要涉及到方面的内容,对于ASPjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
购物车-<%= sitename %>
我的购物车
选项 |
|
商品信息 |
单价(元) |
数量 |
金额 |
操作 |
<%
dim proId,act,qty,k,rs
act=Request.QueryString("act")
proId=Request.QueryString("proId")
qty=Request.QueryString("qty")
if act<>"" then
If uCart.CheckItem(proId)=False Then
set rs = Server.CreateObject("adodb.recordset")
rs.open "select productName,discount_price,pic from Product where id="&proId,conn,1,1
if not rs.eof then
call uCart.AddItem(proId,rs("productname"),rs("discount_price"),0,0,qty,rs("pic"))
end if
rs.close
set rs=nothing
else
call uCart.ModifItem(proId,qty,2)
end if
end if
if uCart.CheckEmtpy=False Then
myCart=uCart.ViewCart()
k=0
For i=LBound(myCart,2) To UBound(myCart,2)
If myCart(0,i)<>"" Then '以前的判断语句
%>
|
 |
<%=myCart(1,i)%> |
¥<%=FormatNumber(myCart(2,i),2,-1)%> |
 |
¥<%=FormatNumber(myCart(5,i)*myCart(2,i),2,-1)%> |
删除 |
<%
k=k+1
end if
Next
myprice=uCart.TPrice()
else
Response.Write("暂无购买商品,请继续 购物 | ")
end if
%>
cart.js
$(function(){
//getTotalPrice();
//手动修改商品数量
var regNum = /^\d+$/;
$(".changeNum").unbind("blur").bind("blur", function () {
var obj = $(this);
var product_num = obj.val();
if(regNum.test(product_num) && product_num > 0){
var buy = parseInt($(this).data("buy"));
product_num = parseInt(product_num);
changeProductNum(obj, product_num - buy,'input');
}else{
alert("商品数量格式不正确");
$(this).val($(this).data("buy"));
return;
}
});
//增加商品数量
$('.addNum').unbind("click").bind("click", function () {
var obj = $(this);
changeProductNum(obj, 1, 'add');
});
//减少商品数量
$('.minusNum').unbind("click").bind("click", function () {
var obj = $(this);
var $itemNum = $(this).closest("tr").find("input[name='pro_num']").val();
if(parseInt($itemNum) > 1){
changeProductNum(obj, -1, 'add');
}
});
//删除商品 展示弹框
$('.btn_del').click(function(){
$(this).next().show();
var url = $(this).attr('href');
});
//取消删除商品
$(".reset_delete").unbind("click").bind("click", function () {
$(this).parents(".pop_box").hide();
});
//执行删除商品
$(".do_delete").unbind("click").bind("click", function () {
//$(this).parents(".pop_box").hide();
var parent = $(this).parents('tr');
parent.remove();
getTotalPrice();
});
//批量删除购物车商品
$('#del-all').click(function(){
var product_id=[];
$('.product_select').each(function(index,element){
if($(this).prop("checked")){
product_id.push($(this).closest("tr").attr('rel'));
}
});
if(product_id.length == 0){
alert('请先选择商品');
return false;
}
if(confirm("确认删除商品")){
var del_confirm = function(product_id){
$("tr[rel='"+product_id+"']").remove();
getTotalPrice();
};
for(var i in product_id){
del_confirm(product_id[i]);
}
}
return false;
});
//勾选计算
$('.check-product').unbind("click").bind("click", function () {
$(this).toggleClass('cur');
var tmp=$('.check-product');
if(tmp.length==tmp.filter('.cur').length){
$('.check-all').addClass('cur');
$('.check-all').prop("checked",true);
}else{
$('.check-all').removeClass('cur');
$('.check-all').prop("checked",false);
}
getTotalPrice();
});
//全选/全不选计算
$('.check-all').click(function(){
$(this).toggleClass('cur');
if($(this).hasClass('cur')){
$('.check-product').addClass('cur');
$('.check-all').addClass('cur');
$('.check-product').prop("checked",true);
}else{
$('.check-product').removeClass('cur');
$('.check-all').removeClass('cur');
$('.check-product').prop("checked",false);
}
getTotalPrice();
});
//结算
$("#settlement").click(function(e){
e.stopPropagation();
e.preventDefault();
var product_ids=[],num_ids=[];
$('.check-product').each(function(index,element){
if($(this).prop('checked')){
var $tr2=$(this).closest("tr");
product_ids.push($tr2.attr("rel"));
num_ids.push($tr2.find("input[name='pro_num']").val());
}
});
if(product_ids.length < 1){
alert("请选择商品");
return ;
}
else{
$.post("changeProductNum.asp",{"act":"settlement","productIds":product_ids.toString(),"numIds":num_ids.toString(),rnd:new Date().getTime()},function(msg){window.location.href='shop.asp';});
}
});
});//the end of window.onload by quwei
function checkBtn(){
var tmp=$('.check-product');
if(tmp.length==tmp.filter('.cur').length){
$('.check-all').addClass('cur');
}else{
$('.check-all').removeClass('cur');
}
}
//商品数量变更
function changeProductNum(obj,inputVal,type){
var $tr = obj.closest("tr"),product_id=$tr.attr("rel");
var $itemNum = $tr.find("input[name='pro_num']");
if($tr.size() > 0){
$itemNum.val(parseInt($itemNum.val()) + inputVal);
var itemPrice = parseFloat($tr.find("td.td4 .c_red").attr("value"));
$tr.find("td.td6 p").text("¥ "+ (parseFloat($itemNum.val())*itemPrice).toFixed(2));
}
getTotalPrice();
}
//价格计算
function getTotalPrice(){
var total_price = total_number = 0;
$('.check-product').each(function(index,element){
if($(this).prop('checked')){
var $tr2=$(this).closest("tr");
total_price += parseFloat($tr2.find("td.td4 .c_red").attr("value")) * parseInt($tr2.find("input[name='pro_num']").val());
total_number += parseInt($tr2.find("input[name='pro_num']").val());
}
});
if($(".CartNum").size() > 0)$(".CartNum").html(total_number);
$('#totalPrice .total_pri_blod').html(total_price.toFixed(2));
}
changeProductNum.asp
<%
dim act
act=Request.Form("act")
if act="settlement" then
call order_settlement()
end if
sub order_settlement()
productIds=Request.Form("productIds")
numIds=Request.Form("numIds")
uCart.RemoveAll()
Set rs = Server.CreateObject("ADODB.Recordset")
if InStr(productIds,",")>0 then
arrPro=split(productIds,",")
arrNum=split(numIds,",")
For i=0 To UBound(arrPro)
rs.open "select productName,discount_price,pic from Product where id="&arrPro(i),conn,1,1
if not rs.eof then
if uCart.CheckItem(arrPro(i))=False then
call uCart.AddItem(arrPro(i),rs("productname"),rs("discount_price"),0,0,arrNum(i),rs("pic"))
else
call uCart.ModifItem(arrPro(i),arrNum(i),2)
end if
end if
rs.close
Next
Else
rs.Open "select productName,discount_price,pic from Product where id="&productIds,conn,1,1
If Not rs.EOF Then
if uCart.CheckItem(productIds)=False then
call uCart.AddItem(productIds,rs("productname"),rs("discount_price"),0,0,numIds,rs("pic"))
else
call uCart.ModifItem(productIds,numIds,2)
end if
End If
rs.Close
End If
Set rs=Nothing
end sub
closeconn
%>
cart.asp