0
所以,我在这里要做的是onClick添加另一个<li>,它完全像它上面那个。我已经在PHP中创建了一个for循环来在这个<li>中创建适当的字段。jQuery添加新字段
我正在运行的问题是:当您单击.repatable-add按钮时,我得到两次“替换前”警报,“替换后”警报根本不会触发。 和想法?
jQuery('.repeatable-add').click(function() {
field = jQuery(this).siblings('ul.image-details').find('li:last').clone(true);
fieldLocation = jQuery(this).siblings('ul.image-details').find('li:last');
jQuery('input', field).val('').attr('name', function(index, name) {
alert(name +' before replace');
return name.replace(/(\d+)/, function(fullMatch, n) {
return Number(n) + 1;
alert(name +' after replace');
});
})
field.insertAfter(fieldLocation, jQuery(this).siblings('ul.image-details').find('li:last'))
return false;
});