ここに私のHTMLがあります::
<fieldset>
<legend>Attributes</legend>
<div class="attr_container">
<div class="attr_entry existent row">
<div class="half">
<label for="attribute[]">Attribute</label>
<input id="attribute" maxlength="50" required="required" name="attribute[]" type="text">
<p>
<a href="javascript:void(0)" class="add_attr"><i class="fa fa-plus-circle"></i> Add Another Attribute</a>
<span class="remove">|
<a href="javascript:void(0)" class="remove_attr"><i class="fa fa-minus-circle"></i> Remove</a></span>
</p>
</div>
<div class="half">
<label for="designator">Is this attribute a designator?</label> <input checked="checked" name="designator[0]" type="radio" value="0" id="designator[0]"> No
<input name="designator[0]" type="radio" value="1" id="designator[]"> Yes
</div>
</div>
</div>
</fieldset>
これが私のjQueryです:
$('.add_attr').click(function() {
// clone and add
$( ".attr_entry:first" ).clone(true).removeClass('existent').insertAfter( ".attr_entry:last" );
});
$('.remove_attr').click(function() {
// remove entry
if($(this).parents('.attr_entry').first().hasClass('existent')) {
alert('You can not remove the first attribute entry.');
} else {
$(this).parents(".attr_entry").first().remove();
}
});
したがって、これを複製するときに、 name 属性を .. に変更する方法を知りたいdesignator[1]
ので、それに追加します。最後に追加されたクローンの後にクローンを作成して挿入する方法がわかりません。
ラジオボタンの配列を受け入れる方法を理解するために参照したHTMLは次のとおりです。
PHP の for ループで実行できる属性を知り、それに属する適切な指定子を取得する必要があるためです。
助けてくれてありがとう!