如何解析 jQuery 选择中的数字?
我正在对各种单选按钮执行选择,这些按钮的类以名称 radio-selection 开头,末尾有一些数字(例如 radio-button1、radio-button2 等)。如果单击单选按钮,则需要启用或禁用该单选按钮包含的某些字段。好的部分是需要启用的类与单选按钮# 匹配(例如radio-option1、radio-option2 等)。
到目前为止,我有这个......
$('input:radio[class^=radio-selection]').live('click', function () {
enableDataGroup($(this).siblings('.radio-option1'));
disableDataGroup($(this).siblings('.radio-option2'));
});
我只是想证明启用和禁用工作(这些是我自己的功能,因为启用和禁用可能会变得有点复杂),但现在我需要以某种方式解析无线电中的数值单击按钮并启用该数据组,并禁用所有其他不匹配的数据组。这是我想要做的伪代码。不幸的是,我不确定在谷歌中搜索什么可以教我如何解析和添加这些数值。
$('input:radio[class^=radio-selection]').live('click', function () {
var i = // Parse off the number off the selector of $(this).
enableDataGroup($(this).siblings('.radio-option' + i));
// Disable every other .radio-option[X] where [X] != i
});
I am performing a selection on various radio buttons whose class starts with the name radio-selection and has some number at the end (e.g. radio-button1, radio-button2, etc). If the radio button is clicked, certain fields contained with that radio button need to be enabled or disabled. The good part is that the class of the that needs to be enabled matches the radio button # (e.g. radio-option1, radio-option2, etc).
So far, I have this...
$('input:radio[class^=radio-selection]').live('click', function () {
enableDataGroup($(this).siblings('.radio-option1'));
disableDataGroup($(this).siblings('.radio-option2'));
});
I just wanted to prove enabling and disabling works (those are my own functions as the enable and disable can become a bit complicated), but now I need to somehow parse off the numeric value off the radio button that is clicked and enable that data group, and disable all others that don't match. Here is the pseudo-code for what I want to do. Unfortunately, I'm not sure what to search for in Google that will teach me how to parse off and add those numeric values.
$('input:radio[class^=radio-selection]').live('click', function () {
var i = // Parse off the number off the selector of $(this).
enableDataGroup($(this).siblings('.radio-option' + i));
// Disable every other .radio-option[X] where [X] != i
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,先对所有内容应用批量操作,然后启用您真正想要启用的操作通常会更容易。
It's generally easier to apply a bulk action to everything first and then just enable the one that you actually want to be enabled.