<script type=
"text/javascript"
>
$(
function
(){
function
totalMoney(){
var
total_price = 0;
var
total_count = 0;
$(
".d1-input"
).each(
function
(){
if
($(this).hasClass(
'status'
)) {
var
obj1 = $(this).parent().siblings(
".d4"
).find(
".count"
).val();
total_count += parseInt(obj1);
var
obj2= $(this).parent().siblings(
".d5"
).find(
".cart-price"
).text();
total_price += parseInt(obj2);
}
});
$(
".item"
).text(total_count);
$(
".total"
).text(total_price);
}
$(
".d-input"
).toggle(
function
(){
$(this).addClass(
"status"
);
$(
".sc-mid-list .d1-input"
).addClass(
"status"
);
$(
".sc-mid-list"
).addClass(
"mouseover"
);
totalMoney();
},
function
(){
$(this).removeClass(
"status"
);
$(
".sc-mid-list .d1-input"
).removeClass(
"status"
);
$(
".sc-mid-list"
).removeClass(
"mouseover"
);
totalMoney();
});
$(
".d1-input"
).toggle(
function
(){
$(this).addClass(
"status"
);
$(this).parents(
".sc-mid-list"
).addClass(
"mouseover"
);
totalMoney();
},
function
(){
$(this).removeClass(
"status"
);
$(this).parents(
".sc-mid-list"
).removeClass(
"mouseover"
);
totalMoney();
});
function
count
(){
$(
".count"
).each(
function
(){
var
num = $(this).val();
if
(num == 1) {
$(this).siblings(
".reduce"
).removeClass(
"two"
).addClass(
"one"
);
$(this).siblings(
".reduce"
).attr(
"disabled"
,
"disabled"
);
}
else
{
$(this).siblings(
".reduce"
).removeClass(
"one"
).addClass(
"two"
);
}
})
}
$(
".sc-mid-list .add"
).click(
function
(){
var
input = $(this).siblings(
".count"
);
var
obj = $(this).parents(
".d4"
);
var
per = parseFloat(obj.siblings(
".d3"
).find(
".per"
).text());
var
num =
''
;
var
price =
''
;
input.attr(
"value"
, parseInt(input.attr(
"value"
)) + 1 );
num = input.attr(
"value"
);
price = num*per;
obj.siblings(
".d5"
).find(
".cart-price"
).text(price);
count
();
totalMoney();
})
$(
".sc-mid-list .reduce"
).click(
function
(){
var
input = $(this).siblings(
".count"
);
var
obj = $(this).parents(
".d4"
);
var
per = parseFloat(obj.siblings(
".d3"
).find(
".per"
).text());
var
num =
''
;
var
price =
''
;
var
Val = parseInt(input.attr(
"value"
));
if
(Val <= 1){
Val = 2;
}
input.attr(
"value"
, parseInt(Val) - 1 );
num = input.attr(
"value"
);
price = num*per;
obj.siblings(
".d5"
).find(
".cart-price"
).text(price);
count
();
})
})
</script>