0
嗨看來,你都將得到我敢從我附上的圖片面臨的問題。我會與你分享我的Html代碼。請幫助我與jsfiddle :)。所有幫助將不勝感激。謝謝大家提前
HTML:
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Where are you starting from</label>
<input type="text" name="start[]" class="form-control" placeholder="ex: Banglore">
</div>
<div class="col-md-6">
<label>Where do you want to go</label>
<input type="text" name="destination[]" class="form-control dest" placeholder="ex: Some Other Places">
</div>
</div>
</div>
<div class="form-group multiple-form-group">
<div class="form-group input-group">
<div class="col-md-6 pad-left-0">
<input type="text" name="start[]" class="form-control start" placeholder="ex: Intermediate place"/>
</div>
<div class="col-md-6 pad-right-0">
<input type="text" name="destination[]" class="form-control dest" placeholder="ex: Intermediate place"/>
</div>
<span class="input-group-btn"><button type="button" class="btn btn-default btn-add">+
</button></span>
</div>
</div>
的Javascript:
<script>
(function ($) {
$(function() {
var addFormGroup = function (event) {
event.preventDefault();
var $formGroup = $(this).closest('.form-group');
var $multipleFormGroup = $formGroup.closest('.multiple-form-group');
var $formGroupClone = $formGroup.clone();
$(this)
.toggleClass('btn-default btn-add btn-danger btn-remove')
.html('–');
$formGroupClone.find('input').val('');
$formGroupClone.insertAfter($formGroup);
$formGroupClone.attr('id', 'test' + (parseInt(/test(\d+)/.exec($(this).attr('id'))[1], 10)+1)).appendTo('#main')
var $lastFormGroupLast = $multipleFormGroup.find('.form-group:last');
if ($multipleFormGroup.data('max') <= countFormGroup($multipleFormGroup)) {
$lastFormGroupLast.find('.btn-add').attr('disabled', true);
}
};
var removeFormGroup = function (event) {
event.preventDefault();
var $formGroup = $(this).closest('.form-group');
var $multipleFormGroup = $formGroup.closest('.multiple-form-group');
var $lastFormGroupLast = $multipleFormGroup.find('.form-group:last');
if ($multipleFormGroup.data('max') >= countFormGroup($multipleFormGroup)) {
$lastFormGroupLast.find('.btn-add').attr('disabled', false);
}
$formGroup.remove();
};
var countFormGroup = function ($form) {
return $form.find('.form-group').length;
};
$(document).on('click', '.btn-add', addFormGroup);
$(document).on('click', '.btn-remove', removeFormGroup);
});
})(jQuery);
$(function() { // <== Doc Ready
$(".dest").change(function() { // When the email is changed
$('.start').val(this.value); // copy it over to the mail
});
});
</script>
朋友您好,感謝您的善意回覆,但上面的功能不加工。它甚至不復制文本。如果你寫錯了,請檢查它。謝謝:) – Siddharth
我無法理解您的HTML。似乎有很多DIV使用'class =「form-group」',它們都嵌套在一起。我無法弄清楚它應該填入的'dest'和'start'之間的關係。最外層的'form-group'沒有獨特的類,我認爲這是我需要用'查找的。 closest'。 – Barmar
嗨,朋友,我可以理解你,我已經做出了修改,並刪除了不必要的表單組。請現在檢查出來,讓我知道我錯了:-)。謝謝 – Siddharth