js怎么做一个输入框,后面带加减号(类似淘宝),如下图
2个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
var a = 1;
function add() {
a++;
document.getElementById("txt").value = a;
}
function sub() {
a--;
document.getElementById("txt").value = a;
}
</script>
</head>
<body>
<div style="width: 80px; height: 30px;">
<div style="width: 64px; height: 30px; float: left; background: red;">
<input id="txt" type="text" style="width: 60px; height: 28px;"
value="1" />
</div>
<div style="width: 15px; height: 30px; float: right;">
<a onclick="javascript:add()"
style="height: 15px; text-align: center; background: gray;"> + </a>
<a onclick="javascript:sub()"
style="height: 15px; text-align: center; background: gray;"> - </a>
</div>
</div>
</body>
</html>
2018-06-08
展开全部
<div class="calc" style="width:80px;height:40px;display:flex;">
<input style="width:60px;height:40px;text-align:center;" type="number" class="" value="0">
<div style="width:20px;height:40px;">
<div class="symbol">+</div>
<div class="symbol">-</div>
</div>
</div>
样式:
.symbol{
width:20px;
height:20px;
background: #F1F1F1;
border:1px solid #bbb;
display:flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
<input style="width:60px;height:40px;text-align:center;" type="number" class="" value="0">
<div style="width:20px;height:40px;">
<div class="symbol">+</div>
<div class="symbol">-</div>
</div>
</div>
样式:
.symbol{
width:20px;
height:20px;
background: #F1F1F1;
border:1px solid #bbb;
display:flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询