偏移量在标头固定中未定义
offset is undefined in Header Fixed
>我现在有一个代码来修复我的表的标题,它工作正常。但是这个函数有一个警告:
Error: TypeError: $(...).offset(...) is undefined
我的代码(我使用引导):
function goheadfixed(classtable) {
$(classtable).wrap('<div class="fix-inner">');
$('.fix-inner').wrap('<div class="fix-outer" style="position: relative;"></div>'); //this is relative cause the header will be absolute
$('.fix-outer').append('<div class="fix-head"></div>');
$('.fix-head').prepend($('.fix-inner').html()); // agrego la tabla
$('.fix-head table').find('caption').remove();
//$('.fix-head table').removeAttr('style');
$('.fix-head table').css('width','100%');
$('.fix-head').css('width', $('.fix-inner table').outerWidth(true)+'px');
$('.fix-head').css('height', $('.fix-inner table thead').outerHeight(true)+'px');
var ithead = parseInt($('.fix-inner table thead').offset().top);
var divfix = parseInt($('.fix-inner').offset().top);
var itop = ithead-divfix;
$('.fix-head').css({'position':'absolute', 'overflow':'hidden', 'top': itop+'px', 'left':0, 'z-index':100 });
$(window).scroll(function () {
var vscroll = $(window).scrollTop();
if(vscroll >= ithead)
$('.fix-head').css('top',(vscroll-divfix)+'px');
else
$('.fix-head').css('top', itop+'px');
});
/* If the windows resize */
$(window).resize(goresize);
}
function goresize() {
$('.fix-head').css('width', $('.fix-inner table').outerWidth(true)+'px');
$('.fix-head').css('height', $('.fix-inner table thead').outerHeight(true)+'px');
}
我调用我的函数:
goheadfixed('table.fixed');
然后当我把其他代码 javascript 放在下面时,我的代码不起作用,但当放在上面时,它工作正常!
:如何删除此警告?
编辑(添加作为答案发布的详细信息):哦。对不起,我忘了说"警告"仅在我不使用该功能时才出现。
如果我调用 funcion goheadfixed('table.fixed'); 好吧,但是如果我不调用这个函数,就会显示警告。
在第 14 行,$('.fix-inner table thead')
要么指不存在的元素,要么是隐藏的元素。听起来好像你找到了至少一个display:none
集合的元素,因此它返回了一个未定义的数字。
要解决此问题,您可以为每个元素添加可见的选择器$("thead:visible")
。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- 使用javascript ajax post方法的未定义偏移PHP错误
- 获取 无法读取未定义的引导轮播脚本的属性“偏移宽度”
- 无法获取属性'偏移'的未定义引用或null引用
- Javascript日期(yyyy-mm-ddThh:mm:ss偏移量)未正确转换
- 类型错误: $(..).偏移量(..)未定义,偏移量存在
- 未定义的偏移量:爆炸“/”后为 1
- 如何添加新的输入行并插入数据库并出现错误 未初始化的字符串偏移量:0 in
- 滚动到页面上的 ID 未正确计算偏移量
- 偏移 JavaScript 滚动:无法读取未定义错误的属性“top”
- 用菜单偏移量自定义Angular SlideAndPush指令
- 未定义的偏移量:0
- 为什么我得到一个未定义的偏移:124在这个for循环中
- Php未定义偏移:0 1 2 3 4 5 6等
- 未定义的偏移量1:当使用ajax文件上传传递文件时
- preg_match错误,货币转换器,未定义偏移量:1
- 引导:“无法读取未定义的属性'偏移宽度'”轮播错误
- 偏移量在标头固定中未定义