1

動的な ID と値を持つこれらの動的ドロップダウンがあります。

<select id=extra['123']></select>
<select id=extra['453']></select>
<select id=extra['789']></select>

PHPでは、次を使用して値を取得できます。

$_REQUEST['extra']

そして、配列を取得します。

[extra] => Array
    (
        [123] => 0
        [453] => 0
        [789] => 0
    )

しかし、jqueryで配列を作成するにはどうすればよいですか? 前もって感謝します!

4

1 に答える 1

4

ワイルドカードが使える

ライブデモ

selectArray = $('[id^=extra]');

すべての選択を繰り返す

selectArray.each(function() {
    alert(this.id);
})​

選択のIDで数字を取得するため

ライブデモ

selectArray = $('[id^=extra]');
ids = selectArray.map(function() {
    return this.id.replace("extra['", "").replace("']", "");
}).get().join();
alert(ids);
​
于 2012-11-23T07:03:27.303 に答える