就在这里是我的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();
}
});
所以,当我克隆此,我想知道如何将名称属性更改为designator[1]
..因此添加一个。我不知道如何做到这一点,而仍然克隆和插入最后一个附加克隆后。
这里是我引用弄清楚如何接受单选按钮的数组的HTML:
Radio buttons + array elements
因为我需要知道我可以在我的PHP for循环做的属性和抢权指定者属于它。
感谢您的帮助!
http://api.jquery.com/attr/ –
我知道有生成的attr()方法。我只是不确定如何在克隆操作发生之前这样做,因为在克隆之后,它会删除第一个单选按钮选项并将其放在该单选按钮上,这样每个选项都不能被选中。 – user3130415