javascript - 如何通过jquery保持div的大小?

标签 javascript jquery css

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

所以我上面有这段代码,类 invoice_resend 是一个 div,当单击按钮时它将被隐藏,如上所示,#update_paid.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。

最佳答案

代替 show() hide()

使用CSS属性

visibility:visible; 

visibility:hidden; 

A sample demo在这里找到。

如果你检查,事件元素有它的 height 甚至 visible

关于javascript - 如何通过jquery保持div的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18329495/

相关文章:

html - 在 html 标记或 adsense 广告中预留空间

javascript - 是否有可编程的方法来确定 <div> 是否溢出

javascript - 与 jquery 中的 'this' 关键字混淆

javascript - jquery 显示和隐藏 mouseout() 问题

jquery - 流沙替代品

c# - Javascript ajax 调用无法访问我的 Web API Controller 页面。似乎无法获取正确的网址

css - 将一个 div 放在另一个圆形 div 的边框上

css - 使用 CSS 突出显示图像?

javascript - Testcafe 抛出错误 invalid arg type

javascript - 我可以在 _app.js 和页面中使用 getInitialProps 吗?