0
$('.invoice_resend').hide();
$('.invoice_resend #update_paid').hide(); 
$('.invoice_send').hide();

所以我上面有这段代码,classinvoice_resend是一个 div,当单击按钮时,它会被隐藏,如上图所示,#update_paidand.invoice_send也将被隐藏,给我留下一个“ RESIZED DIV ”元素。

我想要的是,当所有其他元素都被隐藏时,.invoice_resend div将保持其高度或任何需要编辑的内容。

编辑:

好的,这是我的整个代码:

if (selected_tab == 0) { //Released tab


$('.invoice_resend').hide();
$('.invoice_send').show();
}
else if ( selected_tab == 1 ) { //Invoiced tab


$('.invoice_resend').show();
$('.invoice_resend #update_paid').show(); 
$('.invoice_send').hide();
}
else if ( selected_tab == 2 ) { //Paid tab


$('.invoice_resend').show();
$('.invoice_resend #update_paid').hide(); 
$('.invoice_send').hide();
}
else if ( selected_tab == 3 ) { //Pending tab


$('.invoice_resend').hide();
$('.invoice_resend #update_paid').hide(); 
$('.invoice_send').hide();
}

似乎css.({visibility: 'hidden' or 'visible'})完成了这项工作,但产生了另一个问题。你看,我有几个标签,所以当我点击隐藏所有元素的最后一个标签时,当我点击另一个标签时,它会变得不稳定,显示或隐藏随机元素。上面的代码是我的原始代码,我根据您的回答将其全部编辑为 .css。

4

4 回答 4

5

代替show() hide()

使用 CSS 属性

visibility:visible; 

visibility:hidden; 

在此处找到示例演示

如果你检查,如果元素有它height甚至没有visible

于 2013-08-20T07:44:09.830 回答
2
$('.invoice_resend #update_paid').css({ visibility: 'hidden' });

来自 MDN 文档:

    The visibility CSS property has two purposes:

 1. The hidden value hides an element but leaves space where it would
    have been.

 2. The collapse value hides rows or columns of a table. It also
    collapses XUL elements.

对于已编辑的问题:

if (selected_tab == 0) { //Released tab


$('.invoice_resend').hide();
$('.invoice_send').show();
}
else if ( selected_tab == 1 ) { //Invoiced tab


$('.invoice_resend').show();
$('.invoice_resend #update_paid').css({ visibility: 'visible' }); 
$('.invoice_send').hide();
}
else if ( selected_tab == 2 ) { //Paid tab


$('.invoice_resend').show();
$('.invoice_resend #update_paid').css({ visibility: 'hidden' }); 
$('.invoice_send').hide();
}
else if ( selected_tab == 3 ) { //Pending tab


$('.invoice_resend').hide();
$('.invoice_resend #update_paid').css({ visibility: 'hidden' }); 
$('.invoice_send').hide();
}
于 2013-08-20T07:53:59.607 回答
0

只需制作另一个 div 并将 invoice_resend div 放入其中并在 css 中设置父 div 的宽度和高度。

于 2013-08-20T07:46:25.883 回答
0

你还可以扩展 jQuery 来制作你自己的显示/隐藏类,并在那里决定做什么:

jQuery.fn.myShow = function() {
    var o = $(this[0]); 
    o.addClass("show").removeClass("hide");
};
jQuery.fn.myHide = function() {
    var o = $(this[0]);
    o.addClass("hide").removeClass("show");
};

$('.invoice_resend').myHide();

.hide {
    visibility:hidden; 
}
于 2013-08-20T07:54:24.443 回答