开发者

jQuery version of Linq's Where()

开发者 https://www.devze.com 2023-01-10 14:46 出处:网络
I want to use jQuery to get the checked radio button out of a radio button set. The form object here is not a jQuery object but ra开发者_运维技巧ther \"normal\" javascript object.

I want to use jQuery to get the checked radio button out of a radio button set.

The form object here is not a jQuery object but ra开发者_运维技巧ther "normal" javascript object.

I want the following:

//"where" should fliter the jQuery Array
var myVal = $(form.RadioSet).where(':checked').val();

I know I can get my results with this:

var myVal = $(form).find('input[name=RadioSet]:checked').val();

But that's a little bit more typing with the "input" and the "name" syntax.

Any ideas?

Thanks,


I think .filter() is what you're looking for...

as in:

var myVal = $(form.RadioSet).filter(':checked').val();


http://api.jquery.com/filter/

var myVal = $(form.RadioSet).filter(':checked').val();


How about using jQuery.grep() ? It may be quite useful.

0

精彩评论

暂无评论...
验证码 换一张
取 消