开发者

jquery - filter on multiple prefixes

开发者 https://www.devze.com 2023-03-28 02:16 出处:网络
How can I filter for all id\'s that begin with \"pre\" or \"radio\"? $.each($(\':input[id^=\"pre\"]\',\':input[id^=\"radio\"]\').serializeArray(), function() {开发者_JS百科

How can I filter for all id's that begin with "pre" or "radio"?

$.each($(':input[id^="pre"]',':input[id^="radio"]').serializeArray(), function() {                                     开发者_JS百科                 


your selector was a bit off:

$('input[id^="pre"], input[id^="radio"]').each(function () {});

or if you want to serialize the set of returned objects:

$('input[id^="pre"], input[id^="radio"]').serializeArray();


Don't break your selectors up as separate strings:

$(':input[id^="pre"], :input[id^="radio"]')

Multiple selectors are a single string.

See this fiddle. I think this is what you're trying to do.


$(":input[id]").filter(function() { return this.id.match(/^(pre|radio)/)});

0

精彩评论

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

关注公众号