add
링크를 통해 새 입력 필드를 추가 할 수있는 양식이 있습니다. 새로 추가 된 각 입력 필드는 remove
링크를 통해 제거 할 수도 있습니다.동적 양식 - DOM 조작
add and remove
링크가 마지막에 추가 된 입력 필드에만 표시되도록하려면 어떻게해야합니까?
$(function() {
$('a.add_input').live('click', function(event) {
event.preventDefault();
var $class = '.' + $(this).closest('div.find_input').find('div').attr('class');
var newDiv = $($class).find('div:first').clone();
//alert(newDiv)
newDiv.append('<a href="" class="remove_input">remove</a>')
newDiv.find('input').each(function() {
$(this).val('');
});
$($class + ':first div:last').before(newDiv);
$(this).prev('a.add_input').remove();
alert(ok)
});
$('a.remove_input').live('click', function(event) {
event.preventDefault();
$(this).closest('div').remove();
});
});
. 자유롭게 롤백하거나 편집 할 수 있습니다. –