jQuery Spinner更改事件

时间:2015-12-15 03:24:39

标签: jquery

我需要对微调器更改值事件做一些事情,但显然我需要在微调框外面点击以获取值,我想在旋转增量点击时立即获得值。

JS Fiddle

<html>
    <head> <!-- head is child of html, sibling of body -->
    </head>
    <body> <!-- body is child of html, parent of p -->
        <p> <!-- p is child of body, parent of span -->
            <span>Hello World</span> <!-- span is child of p, it is not a parent because it doesn't contain any elements -->
        </p> 
    </body>
<html>

http://jsfiddle.net/m8gdhyy5/

2 个答案:

答案 0 :(得分: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" />

答案 1 :(得分:0)

试试这个

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

$(function() {
  $("#spinner").spinner();
  $("#spinner").on("spinstop", function(){
     alert($(this).spinner('value'));
  });
});
相关问题