我可以添加一个带有jQuery的手风琴。但现在我也要删除最后选择的手风琴。我喜欢这样: HTML:
<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();
});
然后将删除所有的手风琴。例如,我有两个手风琴,最后一个 - 必须删除两个。但现在两者都将被删除。
我这样试试:
$('#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 });
但现在既不会删除手风琴
});
答案 0 :(得分:0)
对于链接点击的页面重定向问题,请尝试以下方法:
<a href="#">Klik hier om nog een contactpersoon toe te voegen</a>
用“javascript:void(0)”替换href属性,这将阻止页面加载。
对于前。 :
<a href="javascript:void(0);">Klik hier om nog een contactpersoon toe te voegen</a>