Jquery实现购物车的加减按钮的功能

内容比较少,直接看代码吧。这里没有后台

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<style>
.box{
	width:150px;
	height:50px;
	position:absolute;
	
	left:47%;
	top:50px;
}
#text{
	width:50px;
	text-align:center;
}
</style>
<body>
<script type="text/javascript" src="/Shop/js/jquery-3.3.1.js"></script>
<script>
$(function(){
 var t = $("#text");
 $("#add").click(function(){  
  t.val(parseInt(t.val())+1)
 })
 $("#min").click(function(){
	var x=parseInt(t.val());
	if(x>1){
		  t.val(x-1);
	}
	else
		t.val(1);
 })
})
</script>
</head>
<body>
<div class="box">
<input id="min" name="" type="button" value="-" />
<input id="text" readonly="readonly" name="" type="text" value="3" />
<input id="add" name="" type="button" value="+" />
</div>
</body>
</html>
发布了10 篇原创文章 · 获赞 11 · 访问量 386

猜你喜欢

转载自blog.csdn.net/weixin_44715643/article/details/103922349