"購物_數量選擇"
Bootstrap 3.3.0 Snippet by taironlife

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2 class="text-center">購物_數量選擇</h2> <div class="col-md-6"> <h2 class="text-center">無限制大小</h2> <div class="input-group number-spinner"> <span class="input-group-btn"> <button class="btn btn-default" data-dir="dwn"><span class="glyphicon glyphicon-minus"></span></button> </span> <input type="text" class="form-control text-center" value="1"> <span class="input-group-btn"> <button class="btn btn-default" data-dir="up"><span class="glyphicon glyphicon-plus"></span></button> </span> </div> </div> <div class="col-md-6"> <h2 class="text-center">有限制大小</h2> <div class="input-group number-spinner" style="display: inline-block;width: auto;"> <span class="input-group-btn" style="float: left;width: auto;"> <button class="btn btn-default" data-dir="dwn" style="height: 34;"><span class="glyphicon glyphicon-minus"></span></button> </span> <input name="buy_num" id="buy_num" type="text" class="form-control text-center" value="1" style="width:4em;"> <span class="input-group-btn" style="display: inline-block;"> <button class="btn btn-default" data-dir="up" style="height: 34;"><span class="glyphicon glyphicon-plus"></span></button> </span> </div> </div> </div> </div>
.btn-default{ color: #444444; border-radius: 0; background-color: #E2E2E2; border-color: #8E8E8E; }
$(document).on('click', '.number-spinner button', function () { var btn = $(this), oldValue = btn.closest('.number-spinner').find('input').val().trim(), newVal = 0; if (btn.attr('data-dir') == 'up') { newVal = parseInt(oldValue) + 1; } else { if (oldValue > 1) { newVal = parseInt(oldValue) - 1; } else { newVal = 1; } } btn.closest('.number-spinner').find('input').val(newVal); });

Related: See More


Questions / Comments: