<分区>
我正在尝试做数量系统,我的代码是:
<div class="sp-quantity">
<div class="sp-minus fff"> <a class="ddd" href="#">-</a></div>
<div class="sp-input">
<input type="text" class="quntity-input" value="1">
</div>
<div class="sp-plus fff"> <a class="ddd-plus" href="#">+</a></div>
</div>
<script>
$('.ddd-plus').click(function(){
var $old = $('.quntity-input').val();
var $plus =($old +1);
// var $minus = $old - 1;
$('input').val($plus);
console.log($plus,$old);
});
</script>
<style>.sp-quantity {
width:124px;
height:42px;
font-family:"ProximaNova Bold", Helvetica, Arial;
}
.sp-minus {
width:40px;
height:40px;
border:1px solid #e1e1e1;
float:left;
text-align:center;
}
.sp-input {
width:40px;
height:40px;
border:1px solid #e1e1e1;
border-left:0px solid black;
float:left;
}
.sp-plus {
width:40px;
height:40px;
border:1px solid #e1e1e1;
border-left:0px solid #e1e1e1;
float:left;
text-align:center;
}
.sp-input input {
width:30px;
height:34px;
text-align:center;
font-family:"ProximaNova Bold", Helvetica, Arial;
border: none;
}
.sp-input input:focus {
border:1px solid #e1e1e1;
border: none;
}
.sp-minus a, .sp-plus a {
display: block;
width: 100%;
height: 100%;
padding-top: 5px;
}
</style>
(顺便说一句,只有当我将 jquery 放到控制台时,这段代码才有效,否则它不起作用。
所以当我点击加号时,它应该将输入的值加 1(例如:如果输入的值是 1,它应该是 2 但它变成了 11)
我该如何解决?谢谢