<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8" />
<title>jQuery实现购物车物品数量的加减</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
var t = $("#text_box");
$("#add").click(function(){
t.val(parseInt(t.val())+1)
setTotal();
})
$("#min").click(function(){
t.val(parseInt(t.val())-1)
if(parseInt(t.val())<0){
t.val(0);
}
setTotal();
})
function setTotal(){
//toFixed(2) 表示保留两位小数
$("#total").html((parseInt(t.val())*4).toFixed(2));
}
setTotal();
})
</script>
</head>
<body>
<p>单价:4</p>
<input id="min" name="" type="button" value="-"
style="width:20px;height:20px;margin-top:12px;background:#468CD4;text-align:center;color:#ffffff;"/>
<input id="text_box" name="" type="text" value="4" readonly= "true"
style="width:30px;height:19px; margin-top:12px; border:1px solid #ccc; text-align:center; color:#000;"/>
<input id="add" name="" type="button" value="+"
style="width:20px;height:20px; margin-top:12px; background:#468CD4; text-align:center;color:#ffffff;"/>
<p>总价:<label id="total"></label></p>
</body>
</html>
jQuery实现购物车物品数量的加减
原创
©著作权归作者所有:来自51CTO博客作者风中木偶的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:ajax处理返回的xml格式数据
下一篇:php生成二维码类库
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
购物车的实现(未登录时也可以使用)
平时工作的踩坑记录
redis List 拦截器 -
jquery购物车增减商品数量1-32
html
jquery javascript 前端 html 文本框 -
jqueryjson购物车 jquery实现购物车
简单的购物车效果<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>购物车</title> <link rel="stylesheet" type="text/css" href="css/index
jqueryjson购物车 jquery实现购物车效果 css html 单选按钮