Javascript Jquery购物车计算

Javascript Jquery购物车计算,javascript,jquery,Javascript,Jquery,有小提琴。我在html中找到了price并尝试了total,但在点之后是不允许的 Jquery代码: $(document).ready(function() { var Arrays=new Array(); $('#wrap li').mousemove(function(){ var position = $(this).position(); $('#cart').stop().animate({

有小提琴。我在html中找到了price并尝试了total,但在点之后是不允许的

Jquery代码:

$(document).ready(function() {

    var Arrays=new Array();

    $('#wrap li').mousemove(function(){

        var position = $(this).position();

        $('#cart').stop().animate({

                left   : position.left+'px',

            },250,function(){

        });         
    }).mouseout(function(){

    }); 

    $('#wrap li').click(function(){

        var thisID = $(this).attr('id');

        var itemname  = $(this).find('div .name').html();
        var itemprice = $(this).find('div .price').html();
        var prID = $(this).attr('rel');
        var target="&virtuemart_product_id[]="+prID+"&quantity[]=1";
        $('#checkout').closest('a').attr('href', function(i, currentAttribute){
        return currentAttribute + target;
    });             
        if(include(Arrays,thisID))
        {
            var price    = $('#each-'+thisID).children(".shopp-price").find('em').html();
            var quantity = $('#each-'+thisID).children(".shopp-quantity").html();
            quantity = parseInt(quantity)+parseInt(1);

            var total = parseInt(itemprice)*parseInt(quantity);

            $('#each-'+thisID).children(".shopp-price").find('em').html(total);
            $('#each-'+thisID).children(".shopp-quantity").html(quantity);

            var prev_charges = $('.cart-total span').html();
            prev_charges = parseInt(prev_charges)-parseInt(price);

            prev_charges = parseInt(prev_charges)+parseInt(total);
            $('.cart-total span').html(prev_charges);

            $('#total-hidden-charges').val(prev_charges);
        }
        else
        {
            Arrays.push(thisID);

            var prev_charges = $('.cart-total span').html();
            prev_charges = parseInt(prev_charges)+parseInt(itemprice);

            $('.cart-total span').html(prev_charges);
            $('#total-hidden-charges').val(prev_charges);

            $('#left_bar .cart-info').append('<div class="shopp" id="each-'+thisID+'"><div class="label">'+itemname+'</div><div class="shopp-price"> $<em>'+itemprice+'</em></div><span class="shopp-quantity">1</span><img src="http://blog.urbanomic.com/sphaleotas/archives/Ecology_without_Nature/2011-08-31_-_OOOIII__More_Detailed_Schedule/2011-08-31_-_OOOIII__More_Detailed_Schedule_files/icon_delete13.gif" class="remove" /><br class="all" /></div>');

            $('#cart').css({'-webkit-transform' : 'rotate(20deg)','-moz-transform' : 'rotate(20deg)' });
        }

        setTimeout('angle()',200);
    }); 


    $('.remove').livequery('click', function() {

        var deduct = $(this).parent().children(".shopp-price").find('em').html();
        var prev_charges = $('.cart-total span').html();

        var thisID = $(this).parent().attr('id').replace('each-','');

        var pos = getpos(Arrays,thisID);
        Arrays.splice(pos,1,"0")

        prev_charges = parseInt(prev_charges)-parseInt(deduct);
        $('.cart-total span').html(prev_charges);
        $('#total-hidden-charges').val(prev_charges);
        $(this).parent().remove();

        var prID = $("#" + thisID ).attr('rel');

        var target="&virtuemart_product_id[]="+ prID + "&quantity[]=1";
        $('#checkout').closest('a').attr('href', function(i, currentAttribute){
        return currentAttribute.replace(target, "");
    }); 

    }); 

    $('#Submit').livequery('click', function() {

        var totalCharge = $('#total-hidden-charges').val();

        $('#left_bar').html('Total Charges: $'+totalCharge);

        return false;

    }); 

});

function include(arr, obj) {
  for(var i=0; i<arr.length; i++) {
    if (arr[i] == obj) return true;
  }
}
function getpos(arr, obj) {
  for(var i=0; i<arr.length; i++) {
    if (arr[i] == obj) return i;
  }
}
$(文档).ready(函数(){
var数组=新数组();
$('#wrap li').mousemove(函数(){
var position=$(this.position();
$(“#购物车”).stop().animate({
左:位置。左+像素,
},250,函数(){
});         
}).mouseout(函数(){
}); 
$('#wrap li')。单击(函数(){
var thisID=$(this.attr('id');
var itemname=$(this.find('div.name').html();
var itemprice=$(this.find('div.price').html();
var prID=$(this.attr('rel');
var target=“&virtuemart_product_id[]=”+prID+“&quantity[]=1”;
$('#checkout')。最近('a')。attr('href',function(i,currentAttribute){
返回currentAttribute+目标;
});             
if(包括(数组、thisID))
{
var price=$('#each-'+thisID).children(“.shopp price”).find('em').html();
var quantity=$(“#each-”+thisID).children(“.shopp quantity”).html();
数量=parseInt(数量)+parseInt(1);
var total=parseInt(项目价格)*parseInt(数量);
$(“#each-”+thisID).children(“.shoppprice”).find('em').html(总计);
$('#each-'+thisID).children(“.shopp数量”).html(数量);
var prev_费用=$('.cart total span').html();
前期费用=前期费用-前期费用-前期费用(价格);
前期费用=前期费用+总费用;
$('.cart total span').html(前期费用);
$(“#隐藏费用总额”).val(先前费用);
}
其他的
{
数组。推送(thisID);
var prev_费用=$('.cart total span').html();
prev_费用=parseInt(prev_费用)+parseInt(itemprice);
$('.cart total span').html(前期费用);
$(“#隐藏费用总额”).val(先前费用);
$('left#bar.cart info')。追加(''+itemname+'$'+itemprice+'1
); $('#cart').css({'-webkit transform':'rotate(20deg)',-moz transform':'rotate(20deg)}); } setTimeout('angle()',200); }); $('.remove').livequery('click',function(){ var deletry=$(this.parent().children(.shopp price”).find('em').html(); var prev_费用=$('.cart total span').html(); var thisID=$(this.parent().attr('id').replace('each-',''); var pos=getpos(数组,thisID); 阵列拼接(位置1,“0”) 上一笔费用=上一笔费用-下一笔费用(扣除); $('.cart total span').html(前期费用); $(“#隐藏费用总额”).val(先前费用); $(this.parent().remove(); var prID=$(“#”+thisID).attr('rel'); var target=“&virtuemart_product_id[]=”+prID+“&quantity[]=1”; $('#checkout')。最近('a')。attr('href',function(i,currentAttribute){ 返回currentAttribute.replace(目标“”); }); }); $(“#提交”).livequery('单击',函数()){ var totalCharge=$(“#总隐藏费用”).val(); $('#左#栏').html('总费用:$'+总费用); 返回false; }); }); 功能包括(arr、obj){
对于(var i=0;i您需要使用
parseFloat()
而不是
parseInt()
,因为parseInt将其转换为整数,所以它将小数舍入


嘿,Anton.parseFloat()函数工作正常,但它看起来像$1.09。它一定是$1.090。我如何使用它?对不起,我的jquery不好。更新的fiddle:@ErdalBakkal在哪里添加总值?@ErdalBakkal Nvm我找到了它,你可以使用.toFixed()来获取小数:)我的最后一个问题对不起!当我的价格像2469.99它看起来是2.000美元,它必须是2469.99如何修复?