私はLaravelで使用している動的フォームの入力フィールドのインデックスを数えようとしていますが、それ。クローン時に入力名[0]から[1]にカウントする方法
これは私が使用している私の現在のコードです:
HTML:
<div id="language">
<div class="language">
<div class="row">
<div class="form-group col-md-6 col-sm-6">
<input class="form-control" placeholder="Language" name="language[0][name]" type="text">
</div>
<div class="form-group col-md-6 col-sm-6">
<select class="form-control" title="Language level" name="language[0][level]"><option value="medium">Medium</option><option value="good">Good</option><option value="perfect">Perfect</option></select>
</div>
<p><a href="#" class="addsection">Add Section</a></p>
</div>
</div>
</div>
JS:
//Clone fields
//define template
var template = $('#language .language:first').clone();
//define counter
var sectionsCount = 1;
//add new section
$('body').on('click', '.addsection', function() {
//increment
sectionsCount++;
//loop through each input
var section = template.clone().find(':input').each(function(){
//set id to store the updated section number
var newId = this.id + sectionsCount;
//update for label
$(this).prev().attr('for', newId);
//update id
this.id = newId;
}).end()
//inject new section
.appendTo('#language');
return false;
});
私はフィールドのクローンを作成する場合、どのように私は作ることができます[0]カウントアップ? カウントが下がるフィールドを削除するとどうなりますか?
あなたの質問は、現時点では不明でいるようです。私は何も理解できませんでした! –
答えを見てください@ HiI'mFrogattoは私が必要なものです:) – Albert