id jquery选择器 开头_jQuery选择器帮助-如何查找ID以特定字符开头和结尾的元素...

I have a page that's created dynamically. It can have a number of different radio buttons with ID's like so:

In order to write change functions, I'm doing something like this:

$('[id^=cc-radio-opt-]').live("change", function() {

var idx = $(this).attr('id').split('-').pop();

});

This works well. But now, inside that change function, I need to hide a bunch of other related fields. They are named like this:

I need to be able to grab all the fields whose IDs begin with "cc" and end with the same number as the radio button that's been clicked (determined by the idx variable. I know I can get all the fields that start with "cc" by doing this:

$('[id^=cc-]');

But how can I also indicate that they need to end with whatever idx is? In other words, if the cc-radio-opt-1 radio is clicked, how can I get only cc-number-1 and cc-month-1?

解决方案

Well, you were almost there...

$('[id^=cc-][id$=1]')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值