我正在使用 jQuery slideToggle 来显示隐藏的表格行,但它将显示样式设置为阻止,我需要显示表格行。任何想法我怎么能做到这一点?
提前致谢
我想出了解决这个问题的方法——检查显示是否已设置为阻止(如果元素已被切换为显示),如果设置为所需的显示类型。
$('a.btn').on('click', function() {
$('div.myDiv').slideToggle(200, function() {
if ($(this).css('display') == 'block') $(this).css('display', 'table-row'); // enter desired display type
});
});
inorganik's solution is almost working. But you also need to set the step
callback to change block
to table-row
.
$('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');
}
}
});
您可以使用回调来更改它
$('#tableRowId').slideToggle( function(){
$(this).css('display', 'table-row');
});
只需将此代码添加到回调函数
$(this).css('display','');
只需您可以在css中将其默认为
.block { display: table }
然后在加载页面时可以向上滑动
$(document).ready(function () {
$('.btn').click(function(){
$('.block').slideToggle();
})
$('.block').slideUp();
});
下次它向下滑动时,它会显示:表。