2014-10-04 37 views
1

我將模式中的表單元素添加到父頁面中的表單中。該表單的ID是file_form。從特定/選定表單中移除隱藏的表單元素

但是,當聯合國人員選中複選框時,我還需要刪除任何與file_form表單相關聯的當前隱藏輸入。我已經看到如何通常使用.remove刪除隱藏的表單元素,但不知道如何將它們從特定的表單中刪除?這裏是我的嘗試:

if($(this).is(':checked')) { 
    var thecat = $(this).val(); 

$('#file_form').append('<input type="hidden" name="caty[]" value='+ thecat + ' />'); 
} else { 

$('#file_form').append($('input[type="hidden"][value="'+thecat+'"]').remove()); 

} 

回答

2

使用Attribute Equals Selector [name="value"]

$('#file_form input[type="hidden"]').remove(); 

$('#file_form input[type="hidden"]')找到所有元素中type="hidden input元素與ID file_form

+0

我不想刪除所有輸入。只是具有那個「thecat」價值的具體一個。這是我會用什麼呢?代碼'$('#file_form input [type =「hidden」] [value =''+ thecat +'「]')。remove(); (注意,我試過,它實際上不起作用。) – CRAIG 2014-10-04 16:10:31

+0

@CRAIG可以讓http://jsfiddle.net/或者你有活的鏈接或者你可以重現這個場景。 – 2014-10-04 16:13:03

相關問題