开发者

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)/)});

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜