jquery - filter on multiple prefixes
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)/)});
精彩评论