jquery.ui.spinner 更改

发布于 2024-10-20 02:19:04 字数 590 浏览 7 评论 0原文

我正在尝试使用最新版本的 jquery.ui.spinner.js 。 http://wiki.jqueryui.com/w/page/12138077/Spinner

旋转器正在显示并更新文本框,但我无法弄清楚如何捕获“更改”事件。当您手动更改文本框中的值时会触发它,但当您使用微调器箭头时不会触发。

jquery:

    $('input[name*="opening"]').spinner({ min: 0, max: 100});

    $('#doorsize6w7h-f').spinner().change(function(){
         alert($(this).spinner('value'));
    });

html:

<input type="text" value="0" class="front" id="doorsize6w7h-f" name="opening[0][0]" />

I'm trying to use the latest version of the jquery.ui.spinner.js . http://wiki.jqueryui.com/w/page/12138077/Spinner

The spinners are showing-up and updating the textboxes, but I'm having trouble figuring out how to capture the 'change' event. It triggers when you manually change the value in the textbox, but not when you use the spinner arrows.

jquery:

    $('input[name*="opening"]').spinner({ min: 0, max: 100});

    $('#doorsize6w7h-f').spinner().change(function(){
         alert($(this).spinner('value'));
    });

html:

<input type="text" value="0" class="front" id="doorsize6w7h-f" name="opening[0][0]" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

叹梦 2024-10-27 02:19:04

在微调器控件上附加一个事件,该事件在文本框上调用 change()

$('.ui-spinner-button').click(function() {
   $(this).siblings('input').change();
});

jsFiddle

设置好旋转器后。

Attach an event on the spinner controls that calls change() on your textbox.

$('.ui-spinner-button').click(function() {
   $(this).siblings('input').change();
});

jsFiddle.

After setting up the spinner.

鹿港小镇 2024-10-27 02:19:04

我认为这就是您所需要的:

$('.mySpinner').spinner({          
    stop:function(e,ui){
        alert('Triggered after a spin.');
    }
});

与绑定到按钮的 click 事件不同,这还将检测键盘上向上/向下键的使用。

请参阅此页面了解详细信息和更多活动:
http://api.jqueryui.com/spinner/#entry-examples

I think this is what you need:

$('.mySpinner').spinner({          
    stop:function(e,ui){
        alert('Triggered after a spin.');
    }
});

Unlike binding to the click event of the buttons, this will also detect use of the up/down keys on the keyboard.

See this page for details and more events:
http://api.jqueryui.com/spinner/#entry-examples

妞丶爷亲个 2024-10-27 02:19:04

没有“change”事件,而是使用“spinstop”事件:

$('#doorsize6w7h-f').on("spinstop", function(){
   alert($(this).spinner('value'));
});

文档还建议使用 spinchange 事件,但对我来说有点滞后。

资源: http://api.jqueryui.com/spinner/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DUI%2FSpinner %2Fspinner%26redirect%3Dno#event-change

There is no "change" event, instead use "spinstop" event:

$('#doorsize6w7h-f').on("spinstop", function(){
   alert($(this).spinner('value'));
});

The documentation also suggests spinchange event, but it's kind of laggy for me.

Resource: http://api.jqueryui.com/spinner/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DUI%2FSpinner%2Fspinner%26redirect%3Dno#event-change

久隐师 2024-10-27 02:19:04

好吧,实际上我会通过标准“更改”事件路由更改并捕获所有内容,如下所示:

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

Well, actually I would route changes through standard 'change' event and capture everything, like that:

$('input[name*="opening"]').spinner({
    min: 0,
    max: 100,
    spin: function(event, ui) {
        $(this).change();
    }
});
雨巷深深 2024-10-27 02:19:04

这给了我最流畅的结果:

function betterSpinner(input)
{
    input.spinner(
    {
        spin: function(event, ui)
        {
            // the spin event is raised before the value actually gets changed,
            // so let's update it here before raising the input's change() event.
            input.val(ui.value);
            input.change();
        }
    });
}

$(document).ready(function ()
{
    betterSpinner($("#myInput"));
});

This is giving me the most fluid results:

function betterSpinner(input)
{
    input.spinner(
    {
        spin: function(event, ui)
        {
            // the spin event is raised before the value actually gets changed,
            // so let's update it here before raising the input's change() event.
            input.val(ui.value);
            input.change();
        }
    });
}

$(document).ready(function ()
{
    betterSpinner($("#myInput"));
});
装纯掩盖桑 2024-10-27 02:19:04

我知道这个问题已经有了答案。但我希望这对其他人有帮助。

除了手动编辑值和使用微调器的箭头按钮外,还可以使用键盘上的箭头按钮编辑微调器的值。在这种情况下,我发现 keyup 事件比 Change 事件更强大:

$(document).ready(function(){
    var range_spinner = $('.spinner').spinner(); 

    // hack to trigger input keyup whenever spinner button clicked:
    $('.ui-spinner-button').click(function() { $(this).siblings('input').keyup(); });   

    // keyup will catch any stroke on keyboard
    $('#range').keyup(function(){
       console.log(range_spinner.spinner('value')); 
    });
});

I know this question has already been answered. But I hope this will help others.

Beside manually edit the value and using the spinner's arrow button, one can also edit the value of spinner by using arrow button on keyboard. In this case, I find keyup event is more robust than change event:

$(document).ready(function(){
    var range_spinner = $('.spinner').spinner(); 

    // hack to trigger input keyup whenever spinner button clicked:
    $('.ui-spinner-button').click(function() { $(this).siblings('input').keyup(); });   

    // keyup will catch any stroke on keyboard
    $('#range').keyup(function(){
       console.log(range_spinner.spinner('value')); 
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文