javascript 在更改时获取微调器 ui 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16562389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:09:12  来源:igfitidea点击:

get spinner ui value on change

javascriptjqueryjquery-ui

提问by Kakitori

How could get the value of a spinner when the value is changing with the button up and down?

当值随着按钮的上下变化而变化时,如何获得微调器的值?

<input type="text" id="spinner1" value="1" onchange="selFirt()" readonly>
<script>
    $("#spinner1").spinner({min: 1, max: 5});
function selFirt(){
    $('#spinner1').spinner().change(function(){
        alert($(this).spinner('value'));
    });
}
</script>

回答by PSR

$('input[name*="name"]').spinner({
    min: 0,
    max: 100,
    spin: function(event, ui) {
        $(this).change();
    }
});

SEE HERE

看这里

回答by ebram khalil

try the following :

尝试以下操作:

$(function () {
    var spinner = $("#spinner").spinner({
        step: 2 ,
        spin: function( event, ui ){
            handleSpinnerValue(ui.value);
        }
    });
});
function handleSpinnerValue(txtValue)
{
    //do here whatever you want with the value;
    alert(txtValue);
}