我正在使用 jQuery slideToggle 来显示一个隐藏的表格行,但它将 display 样式设置为 block,而我需要将其设置为 display: table-row。你有什么想法可以实现这个吗?
提前感谢。
提前感谢。
$('a.btn').on('click', function() {
$('div.myDiv').slideToggle(200, function() {
if ($(this).css('display') == 'block') $(this).css('display', 'table-row'); // enter desired display type
});
});
$('row-selector-here').slideToggle({
duration: 'fast',
step: function() {
if ($(this).css('display') == 'block') {
$(this).css('display', 'table-row');
}
},
complete: function() {
if ($(this).css('display') == 'block') {
$(this).css('display', 'table-row');
}
}
});
flex
而不是 table-row
的情况。我还不得不添加另一个 if 子句来检测它是否设置为 none
,并将其设置为 ''
,以便外部 CSS 可以应用而不被覆盖(jQuery 直接干扰元素的 CSS 在 HTML 中,这将覆盖任何地方的 CSS,除非使用 !important
,但我不想使用)。 - Don Cullen$('#tableRowId').slideToggle( function(){
$(this).css('display', 'table-row');
});
slideToggle()
用于显示和隐藏,这样就不能隐藏了。请查看我的答案。 - inorganik只需将此代码添加到回调函数中
$(this).css('display','');
slidetoggle()
可以显示和隐藏,但是使用你的修改方法时它无法隐藏。 - inorganik