Я могу добавить гармошку с jQuery. Но теперь я хочу также удалить последнего выбранного аккордеона. У меня это так: HTML:удалить последний аккордеон с jquery
<div class="span12" id="delete-contact">
<p style="text-align: center;">
<a href="#">Klik hier om contactpersoon te verwijderen</a>
</p>
</div>
JQuery:
$('#delete-contact p a').click(function() {
$(this).parents('.panel').get(0).remove();
});
Но это не работает
Это HTML:
<div class="span12" id="add-contact">
<p style="text-align: center;">
<a href="#">Klik hier om nog een contactpersoon toe te voegen</a>
</p>
</div>
<div class="span12" id="delete-contact">
<p style="text-align: center;">
<a href="#">Klik hier om contactpersoon te verwijderen</a>
</p>
</div>
И это для добавления и удаления аккордеона:
// Add extra contact clicked?
$('#add-contact p a').click(function()
{
// Make a copy of the first input fields
html = $('#new-contact').children().clone();
// Get number of tabs in the accordion
var index = $('#accordion h3').length;
if(index == 0)
{
alert($('#accordion h3').length);
$('#contactpersonen_canorder_0').prop('checked', true);
$('#contactpersonen_canseestock_0').prop('checked', true);
$('#contactpersonen_canseeorders_0').prop('checked', true);
$('#contactpersonen_canaddaddress_0').prop('checked', true);
$('#contactpersonen_canseeprice_0').prop('checked', true);
$('#contactpersonen_canseecredit_0').prop('checked', true);
$('#contactpersonen_canseepickup_0').prop('checked', true);
}
// Remove the values
html.find("input[type=text]").val("");
html.find('input[type=checkbox]').attr('checked', false);
// New 'id', 'for' and 'name' attribute names
html.find('input[type=checkbox]').each(function() {
me = $(this);
attr = me.attr('id');
number = attr.split('_')[2];
newNumber = parseInt(index) + 1;
newAttr = attr.replace(number, newNumber);
me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);
});
// Insert it at the end
$('#accordion').append(html);
$('#accordion').accordion('refresh');
// Set last tab to active
$("#accordion").accordion({ active: index });
// Cancel the click
return false;
});
$('#delete-contact p a').click(function(event)
{
event.preventDefault();
$(this).parents('.panel').eq(0).remove();
//$("#accordion).accordion("destroy"); // Removes the accordion bits
//$("#accordion").empty();
});
Если я это сделать:
$('#delete-contact p a').click(function(event)
{
event.preventDefault();
//$(this).parents('.panel').eq(0).remove();
// $("#accordion).accordion("destroy"); // Removes the accordion bits
$("#accordion").empty();
});
Тогда все accordians будут удалены. Так, например, у меня есть два аккордеона, а последний - два, которые нужно удалить. Но теперь оба будут удалены.
Я стараюсь это так:
$('#delete-contact p a').click(function(event)
{
event.preventDefault();
//$(this).parents('.panel').eq(0).remove();
// $("#accordion).accordion("destroy"); // Removes the accordion bits
$("#accordion").empty({ active: index });
Но теперь ни Accordian будут удалены
});
'получить (0)' получает родной узел DOM, который в некоторых современных браузерах будет иметь 'удалить()' метод, но вы, вероятно, хотел объект JQuery, и что вы будете использовать ' eq (0) '. – adeneo
Итак, я изменил это. Что дальше?? – InfinityGoesAround