我的问题是如何从 Name="phone" 字段中获取所有值
JS
<script>
$(function(){
$(document.body).on('click', '.changeType' ,function(){
$(this).closest('.phone-input').find('.type-text').text($(this).text());
$(this).closest('.phone-input').find('.type-input').val($(this).data('type-value'));
});
$(document.body).on('click', '.btn-remove-phone' ,function(){
$(this).closest('.phone-input').remove();
});
$('.btn-add-phone').click(function(){
var index = $('.phone-input').length + 1;
$('.phone-list').append(''+
'<div class="input-group phone-input">'+
'<input type="number" name="phone" class="form-control" placeholder="(999) 999 9999" />'+
'<span class="input-group-btn">'+
'<button class="btn btn-danger btn-remove-phone" type="button"><span class="glyphicon glyphicon-remove"></span></button>'+
'</span>'+
'</div>'
);
});
});</script>
HTML
<div class="col-sm-10">
<div class="phone-list">
<div class="input-group phone-input">
<span class="input-group-btn">
</span>
<input type="number" name="phone" class="form-control" placeholder="(999) 999 9999" required=""/>
</div>
</div>
<button type="button" class="btn btn-success btn-sm btn-block btn-add-phone"><span class="glyphicon glyphicon-plus"></span> Add Phone</button>
</div>
控制器
@PostMapping("/applicant")
public String saveApplicantToDb(
@Valid @ModelAttribute Applicant applicant,
@RequestParam("phone") int[] phone
) {
if (phone!= null)
System.out.println(phone.length);
_applicantRepository.save(applicant);
return "applicant";
}
温温酱
蛊毒传说
相关分类