简体   繁体   English

无法使用 jquery 解决类型错误

[英]Can't solve a typeerror with jquery

I'm pretty sure this is nothing but as I'm new with coding I'm struggling with this problem.我很确定这没什么,但由于我是编码新手,所以我正在努力解决这个问题。 I'm trying to make my table navigable with arrows but when I use an arrow it just doesn't work.我试图让我的表格可以用箭头导航,但是当我使用箭头时它就不起作用了。 It seems to be because of a TypeError but I can't succeed to understand what's going wrong.这似乎是因为 TypeError 但我无法成功理解出了什么问题。 If anyone could explain that would be great !如果有人能解释那就太好了!

jsFiddle jsFiddle

Problem seems to come from line 60. This problem started with the fact I was using DataTable script.问题似乎来自第 60 行。这个问题始于我使用 DataTable 脚本这一事实。 I then had these lines at the beginning of the js file:然后我在 js 文件的开头有这些行:

// DataTable //
var table = $('#mytable').DataTable( {
    "paging": false,
    "searching": false,
    "info": false,
    fixedHeader: true,
    colReorder: true,
    stateSave: true,
});

But I wanted to remove that script to not depend about anything else (I'm learning by trying to do everything myself).但是我想删除该脚本以不依赖其他任何东西(我正在通过尝试自己做所有事情来学习)。 So I tried to replace it with some vars, but unsuccessfully so far.所以我试图用一些变量替换它,但到目前为止没有成功。 My highlight function looked like this with DataTable:我的亮点 function 在 DataTable 中看起来像这样:

        function highlight() { 
        document.querySelectorAll('.highlight-rc').forEach(col => col.classList.remove('highlight-rc'));            
        var colIdx = table.cell(c).index().column;
        $(table.cells().nodes()).removeClass('highlight-rc');
        $(table.column(colIdx).nodes()).addClass('highlight-rc');
        currCell.removeClass('highlight');
        c.addClass('highlight');  
        currCell.parent().removeClass('highlight-rc');
        c.parent().addClass('highlight-rc'); 
    }

Thanks in advance for your kind help.提前感谢您的帮助。 Sincerely,真挚地,

Thanks to Rory help, I've been able to rethink my function and make it work.感谢 Rory 的帮助,我能够重新考虑我的 function 并使其工作。 I'm posting it here if it can help anyone with the same troubles:如果它可以帮助遇到同样麻烦的任何人,我将其发布在这里:

// Navigate with arrows //
var currCell = $('td').first();
var editing = false;

// User clicks on a cell //
$('td').click(function() {
    currCell = $(this);
    // edit(); //
}); 

// User navigates table using keyboard //
$('#mytable tbody').keydown(function(e) {
    var c = "";
    // Function to make highlight follow the navigation //
    function highlight() {
        document.querySelectorAll('.highlight-rc').forEach(col => col.classList.remove('highlight-rc'));
        currCell.removeClass('highlight');
        var navIndex = $(c).index();
        const columns = document.querySelectorAll(`td:nth-child(${navIndex+1})`);
        columns.forEach(col => {
            col.classList.add('highlight-rc');
        c.addClass('highlight');  
        c.parent().addClass('highlight-rc'); 
        })
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Adobe Animate Javascript TypeError 之谜 - 无法解决 - Adobe Animate Javascript TypeError mystery - can't solve 无法弄清楚如何使用本地存储和 jquery 解决这个问题 - Can't figure out how to solve this using Local Storage and jquery 无法解决Javascript错误未捕获的TypeError:无法调用欠定义的方法“ get” - Can't solve Javascript error Uncaught TypeError:Cannot call method 'get' of underfined 如何解决 IE11 中的“TypeError: Object 不支持属性或方法‘追加’”? - How can I solve “TypeError: Object doesn't support property or method 'append'” in IE11? 如何解决Uncaught TypeError:非法调用jquery ajax - how to solve Uncaught TypeError: Illegal invocation jquery ajax 当jQuery为非冲突模式时,如何解决TypeError迭代器不是prototype.js函数 - How to solve TypeError iterator is not a function with prototypejs when jquery is is noconflict mode 如何解决 jQuery.Deferred 异常:$(...).treemenu(...).openActive is not a function TypeError? - How to solve the jQuery.Deferred exception: $(...).treemenu(...).openActive is not a function TypeError? 无法读取jQuery cookie,但可以设置它们,“ Uncaught TypeError:$。cookie不是函数” - Can't read jQuery cookies but can set them, “Uncaught TypeError: $.cookie is not a function” "我该如何解决 - Uncaught TypeError: removeIndividualBook is not a function?" - How can I solve - Uncaught TypeError: removeIndividualBook is not a function? 类型错误:无法读取 null 的属性“长度”,我该如何解决? - TypeError: Cannot read property 'length' of null, how can i solve it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM