// Jquery
$(document).on('click', '.value-control', function () {
var action = $(this).attr('data-action')
var min = $(this).attr('data-min')
var max = $(this).attr('data-max')
var target = $(this).attr('data-target')
var value = parseFloat($('[id="' + target + '"]').val());
if (action == "plus") {
if (value < max) {
value++;
}
}
if (action == "minus") {
if (value > min) {
value--;
}
}
$('[id="' + target + '"]').val(value)
})
//Html Code
<div class="input-group">
<span class="input-group-btn"><button class="btn btn-default value-control" data-action="minus" data-min="0" data-target="font-size"><span class="glyphicon glyphicon-minus"></span></button></span>
<input type="text" value="1" class="form-control" id="font-size" />
<span class="input-group-btn"><button class="btn btn-default value-control" data-action="plus" data-max="9" data-target="font-size"><span class="glyphicon glyphicon-plus"></span></button></span>
</div>
//Reference
http://bootsnipp.com/snippets/a288y
$(document).on('click', '.value-control', function () {
var action = $(this).attr('data-action')
var min = $(this).attr('data-min')
var max = $(this).attr('data-max')
var target = $(this).attr('data-target')
var value = parseFloat($('[id="' + target + '"]').val());
if (action == "plus") {
if (value < max) {
value++;
}
}
if (action == "minus") {
if (value > min) {
value--;
}
}
$('[id="' + target + '"]').val(value)
})
//Html Code
<div class="input-group">
<span class="input-group-btn"><button class="btn btn-default value-control" data-action="minus" data-min="0" data-target="font-size"><span class="glyphicon glyphicon-minus"></span></button></span>
<input type="text" value="1" class="form-control" id="font-size" />
<span class="input-group-btn"><button class="btn btn-default value-control" data-action="plus" data-max="9" data-target="font-size"><span class="glyphicon glyphicon-plus"></span></button></span>
</div>
//Reference
http://bootsnipp.com/snippets/a288y
0 Comments