0

次のような複数の入力フィールドがあります。

<input type="text" name="childage[3]" placeholder="0"/>
<input type="text" name="childage[8]" placeholder="0"/>
<input type="text" name="childage[12]" placeholder="0"/>

それらをjQueryに取り込み、AJAXでphpに渡したいのですが、キー(3、8、12)を覚えています。これは可能ですか?

私は今まで次のことを試しました:

$('input[name="childage[]"]');
$('input[name="childage"');
4

2 に答える 2

3

serializeメソッドを確認する必要があります。

http://docs.jquery.com/Ajax/serialize

次のように、すべてのフォーム要素を取得する必要があります。

<input class="age-box" type="text" name="childage[3]" placeholder="0"/>
<input class="age-box" type="text" name="childage[8]" placeholder="0"/>
<input class="age-box" type="text" name="childage[12]" placeholder="0"/>

var ages = $('.age-box').serialize();
$.post(url, ages, function(data) { //handle response from the server });
于 2013-04-20T19:57:45.977 に答える
0

非表示の入力フィールドを使用して、値を必要な数値に設定できます。

<input type="hidden" value=3 />
<input type="hidden" value=8 />
<input type="hidden" value=12 />

// Get the values
$('input[type="hidden"]')[0].val();
$('input[type="hidden"]')[1].val();
$('input[type="hidden"]')[2].val();
于 2013-04-20T20:04:01.377 に答える