在出生日期内获取单独的值

时间:2017-02-13 13:06:35

标签: javascript jquery dob

我有问题得到"独特"来自此DOB输入字段的值。仅具有类完整日期的最后一个输入字段中的第一行打印值。我使用了这个电话,但方式错误......

JSFIddle

<div class="info-inner">
<input data-age="adt" type="text" class="disabled-number dayter" name="dob passengers[0][birthdate]" maxlength="2" placeholder="dd" min="01" max="31">
<input data-age="adt" type="text" class="disabled-number monther" name="dob passengers[0][birthdate]" maxlength="2" placeholder="mm" min="01" max="12">
<input data-age="adt" type="text" class="disabled-number yearer" name="dob passengers[0][birthdate]" maxlength="4" placeholder="yyyy" min="1930">
<input class="full-date" data-age="adt" type="hidden" name="full-dob" data-min-date-adt="18.03.2017" data-max-date-adt="18.03.2005">
</div>
div class="info-inner">
<input data-age="adt" type="text" class="disabled-number dayter" name="dob passengers[1][birthdate]" maxlength="2" placeholder="dd" min="01" max="31">
<input data-age="adt" type="text" class="disabled-number monther" name="dob passengers[1][birthdate]" maxlength="2" placeholder="mm" min="01" max="12">
<input data-age="adt" type="text" class="disabled-number yearer" name="dob passengers[1][birthdate]" maxlength="4" placeholder="yyyy" min="1930">
<input class="full-date" data-age="adt" type="hidden" name="full-dob" data-min-date-adt="18.03.2017" data-max-date-adt="18.03.2005">
</div>
<div class="info-inner">
<input data-age="cnn" type="text" class="disabled-number dayter" name="dob passengers[2][birthdate]" maxlength="2" placeholder="dd" min="01" max="31">
<input data-age="cnn" type="text" class="disabled-number monther" name="dob passengers[2][birthdate]" maxlength="2" placeholder="mm" min="01" max="12">
<input data-age="cnn" type="text" class="disabled-number yearer" name="dob passengers[2][birthdate]" maxlength="4" placeholder="yyyy" min="1930">
<input class="full-date" data-age="cnn" type="hidden" name="full-dob" data-min-date-ch="18.03.2005" data-max-date-ch="18.03.2015">
</div>

我尝试了这个jquery:

$('.disabled-number').on('change', function(){
    var date = $('.dayter').val() + '.' + $('.monther').val() + '.' + $('.yearer').val();
    $(this).each(function () {
        $('.full-date').val(date);
    });
});

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

$('.disabled-number').on('change', function() {
  var container = $(this).parent();
  var date = container.children('.dayter').val() + '.' + container.children('.monther').val() + '.' + container.children('.yearer').val();
  container.children('.full-date').val(date);
});

请参阅JSFiddle