jQuery 按钮集更改

发布于 2024-10-24 03:07:25 字数 875 浏览 1 评论 0原文

我是 jQuery 的新手,我想在我的应用程序中使用它的按钮集而不是一些单选按钮。此处的文档:http://jqueryui.com/demos/button/#radio

如何将处理程序添加到当按钮组改变值时发生事件?

这是我尝试过的代码片段:

$('input.tod_quant').change(function() {
    alert('TEST');
});

然后在 HTML 中:

<span id="tod_quant" class="buttonset">
        <input type="radio" id="tod_quant5" name="tod_quant" value="5" /><label for="tod_quant5">5-Minute</label>
        <input type="radio" id="tod_quant60" name="tod_quant" checked="checked" value="60" /><label for="tod_quant60">60-Minute</label>
        </span>

“change”事件永远不会触发。是否还有更改事件?我该怎么做?此外,有没有带有示例的文档? http://jqueryui.com 有很多示例,但我找不到一个显示任何事件触发的示例。我想我对 jQuery 的无知并不能完全解决这个问题。

任何帮助将不胜感激。谢谢。

I'm new to jQuery and thought I would use its buttonset instead of some radio buttons on my application. Documentation here: http://jqueryui.com/demos/button/#radio

How do I add a handler to an event when the set of buttons changes value?

Here is a snippet of the code I tried:

$('input.tod_quant').change(function() {
    alert('TEST');
});

And then later on in the HTML:

<span id="tod_quant" class="buttonset">
        <input type="radio" id="tod_quant5" name="tod_quant" value="5" /><label for="tod_quant5">5-Minute</label>
        <input type="radio" id="tod_quant60" name="tod_quant" checked="checked" value="60" /><label for="tod_quant60">60-Minute</label>
        </span>

The "change" event never fires. Is there even a change event? How can I do this? Furthermore, is there any documentation with an example? http://jqueryui.com has plenty of examples, and not a single one that I can find shows any events firing. I suppose my ignorance of jQuery isn't exactly helping the situation.

Any help would be most appreciated. Thank you.

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

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

发布评论

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

评论(4

我们只是彼此的过ke 2024-10-31 03:07:25

jQuery-UI 中的按钮没有 change 事件。

您应该监听底层单选按钮的更改或单击事件:

http://jsfiddle.net/marcosfromero/kr2Xc/

There's no change event for buttons in jQuery-UI.

You should listen to change or click event of the underlying radio-buttons:

http://jsfiddle.net/marcosfromero/kr2Xc/

滥情空心 2024-10-31 03:07:25

哈!问题解决了。我一整天都在研究这个,它就在我面前。

我只需要将选择元素的方式更改为:

$('#tod_quant')

Ha! Problem solved. I've been hacking at this all day, and it was right in front of me.

I just needed to change how I was selecting the element to this:

$('#tod_quant')
街角卖回忆 2024-10-31 03:07:25

我遇到了这个问题,我解决了这个问题,如下所示:
我为标签创建了一个事件处理程序:

$('.label-class').click(LabelClicked);
$('.input-class').change(InputChanged);
function LabelClicked() {
    var input = $('#' + $(this).attr('for'));
    if(input) 
        input.trigger('change'); 
    return true;
}
function InputChanged() {
    //do your work with this event
}

没有其他方法!我尝试了多种方法,最后决定这样做

I had this problem, and I solved this as below:
I created an event handler for labels:

$('.label-class').click(LabelClicked);
$('.input-class').change(InputChanged);
function LabelClicked() {
    var input = $('#' + $(this).attr('for'));
    if(input) 
        input.trigger('change'); 
    return true;
}
function InputChanged() {
    //do your work with this event
}

no other way! I tested several ways and finally decided to do this

迷路的信 2024-10-31 03:07:25
    <script>
    $(function() {
        $( "#radio" ).buttonset();
    });
    </script>



<div class="demo">

<form>
    <div id="radio">
        <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
        <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
        <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
    </div>
</form>

使用此代码并检查是否包含 jquery.js 和 jqueryui.js 文件。

    <script>
    $(function() {
        $( "#radio" ).buttonset();
    });
    </script>



<div class="demo">

<form>
    <div id="radio">
        <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
        <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
        <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
    </div>
</form>

use this code and check whether you are including the jquery.js and jqueryui.js files or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文