获取具有相同名称数组的所有字段值

GSt*_*Sto 1 jquery jquery-selectors

我有一些输入字段,格式如下:

<input name='date_of_birth[month]' type='text' />
<input name='date_of_birth[day]' type='text' />
<input name='date_of_birth[year]' type='text' />
Run Code Online (Sandbox Code Playgroud)

有没有办法在jQuery中选择这些字段的所有值?

use*_*654 5

$.map在这种情况下,该方法可能更好:

var dobArray = $.map($('input[type=text][name^=date_of_birth]'),function(){
  return this.value;
});
Run Code Online (Sandbox Code Playgroud)

并使其成为日期字符串,

var dobString = dobArray.join("/");
Run Code Online (Sandbox Code Playgroud)