jQuery 按钮集更改
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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/
哈!问题解决了。我一整天都在研究这个,它就在我面前。
我只需要将选择元素的方式更改为:
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:
我遇到了这个问题,我解决了这个问题,如下所示:
我为标签创建了一个事件处理程序:
没有其他方法!我尝试了多种方法,最后决定这样做
I had this problem, and I solved this as below:
I created an event handler for labels:
no other way! I tested several ways and finally decided to do this
使用此代码并检查是否包含 jquery.js 和 jqueryui.js 文件。
use this code and check whether you are including the jquery.js and jqueryui.js files or not.