我建立在一個動態的形式,用戶可以不斷添加條目,直到他們滿意,要做到這一點,我用這個JavaScript,以便在某些HTML拉,
$('#add_another').click(function(e){
$.get('/admin/add_grade_course', function(data) {
$('#added_by_ajax').append(data);
});
e.preventDefault();
});
的HTML被返回是一個如下所示,
<fieldset>
<select name="course_type">
<option value="Classroom based learning">Classroom Based Learning</option>
<option value="Apprenticeship based learning">Aprenticeship Based Learning</option>
<option value="On the Job Learning">On The Job Learning</option>
</select>
<label for="course_names">Course Name</label>
<input type="text" name="course_names" value="<?php set_value('course_names');?>"/>
<?php echo form_error('course_names'); ?>
<label for="course_links">Course Links</label>
<input type="text" name="course_links" value="<?php set_value('course_links');?>"/>
<?php echo form_error('course_links'); ?>
<label for="grade_desc">Description of Grades Needed</label>
<textarea name="grade_desc"><?php set_value('grade_desc')?></textarea>
<a href="#" class="remove_fields">Delete</a>
</fieldset>
我的問題是,當你可以看到有什麼獨特之處是動態創建的報名表,如果用戶又增加了一個新的輸入字段,然後決定他們不需要它,我將如何去除最後添加的表單元素?,我假設我需要以某種方式得到th e點擊的.remove_fields
鏈接的父級字段集?我怎麼做,沒有選擇頁面上的所有字段集?