我正在使用Boot Strap微调器,因为如何在加长按钮中获取值并在微调器中按下
by jquery
var spinner = $("#spinner").spinner({
min: 0,
max: 5,
create: function (event, ui) {
//add custom classes and icons
$(this)
.next().addClass('btn btn-success').html('<i class="ace-icon fa fa-plus"></i>')
.next().addClass('btn btn-danger').html('<i class="ace-icon fa fa-minus"></i>')
//larger buttons on touch devices
if ('touchstart' in document.documentElement)
$(this).closest('.ui-spinner').addClass('ui-spinner-touch');
},
});
答案 0 :(得分:0)
请尝试此
if($("#spinner").next().hasClass("btn") && $("#spinner").next().hasClass("btn-success")){
alert("plus")
}
else{
alert("minus")
}
答案 1 :(得分:0)
完成此工作Fiddle
我使用Bootstrap和JQuery创建了New Fiddle。
HTML代码
<div class="container">
<div class="row">
<div class="col-md-3">
<p>Min: -10</p>
<p>Max: 40</p>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="input-group number-spinner">
<span class="input-group-btn data-dwn">
<button class="btn btn-default btn-info" data-dir="dwn"><span class="glyphicon glyphicon-minus"></span></button>
</span>
<input type="text" class="form-control text-center" value="1" min="-10" max="40">
<span class="input-group-btn data-up">
<button class="btn btn-default btn-info" data-dir="up"><span class="glyphicon glyphicon-plus"></span></button>
</span>
</div>
</div>
</div>
JQuery函数
$(function() {
var action;
$(".number-spinner button").mousedown(function () {
btn = $(this);
input = btn.closest('.number-spinner').find('input');
btn.closest('.number-spinner').find('button').prop("disabled", false);
if (btn.attr('data-dir') == 'up') {
action = setInterval(function(){
if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {
input.val(parseInt(input.val())+1);
}else{
btn.prop("disabled", true);
clearInterval(action);
}
}, 50);
} else {
action = setInterval(function(){
if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {
input.val(parseInt(input.val())-1);
}else{
btn.prop("disabled", true);
clearInterval(action);
}
}, 50);
}
}).mouseup(function(){
clearInterval(action);
});
});
简单而敏感。