jQuery 카트 수량 가감 실현

1456 단어
<!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>

좋은 웹페이지 즐겨찾기