2015-12-15 2 views
1

Мне нужно что-то сделать на событии изменения значения spinner, но, видимо, мне нужно щелкнуть за рамкой spinner, чтобы получить значение, я хотел мгновенно получить значение при нажатии на увеличение.jQuery Spinner Change Event

JS Fiddle

$(function() { 
     $("#spinner").spinner({ 
     change: function(event, ui) { 
      console.log(this.value) 
      if (this.value == '1') { 
      alert(this.value) 
      } 
     } 
     }); 
    } 
); 

http://jsfiddle.net/m8gdhyy5/

ответ

0

Попробуйте

http://jsfiddle.net/m8gdhyy5/2/

$(function() { 
    $("#spinner").spinner(); 
    $("#spinner").on("spinstop", function(){ 
    alert($(this).spinner('value')); 
    }); 
}); 
+0

отлично работает, спасибо. – Nevi

1

Вы должны использовать spin event

$(function() { 
 
    $("#spinner").spinner({ 
 
    spin: function(event, ui) { 
 
     snippet.log('value: ' + ui.value) 
 
     if (ui.value == '1') { 
 
     snippet.log('matched: ' + ui.value) 
 
     } 
 
    } 
 
    }); 
 
});
<!-- To show result in the dom instead of console, only to be used in the snippet not in production --> 
 
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 --> 
 
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script> 
 

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<link href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" /> 
 
<input id="spinner" />

;

+0

благодарим вас за ответ. – Nevi