简体   繁体   中英

jQuery - select all inputs with array name

i have a lot of input fields like:

<input type="hidden" value="" name="participants[1][canceled]">
<input type="hidden" value="" name="participants[2][canceled]">
<input type="hidden" value="" name="participants[3][canceled]">

I am looking for a jQuery selector that gives me all of these items. I dont want to use a loop. I would prefer something like:

jQuery('[name="participants[*][canceled]"]') // actually dont work

Is that possible?

Thank you

EDIT: Thanks to all of you

$(':hidden[name^="participants["][name$="][canceled]"]');

Was my solution and works like a charm. Ty

尝试在您的上下文中使用以选择器开头属性

jQuery('[name^="participants"]')

If you just want the array name then you can just use participants

Live Demo

jQuery('[name*=participants]')

To be precise this is the correct way:

$(':hidden[name^="participants["][name$="][canceled]"]');

Or if you need to match numbers only:

$(':hidden').filter(function() {
    return /^participants\[\d+\]\[canceled\]$/.test(this.name);
});

DEMO: http://jsfiddle.net/qbgAL/

我会使用类似$("input:hidden[name^='participants']")

试试这个: Refreence

$('[name ="participants"][name $="[canceled]"]')

尝试这个:

jQuery('[name^="participants"][name$="[canceled]"]')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM