当我尝试在 for 循环中获取表格的所有行的高度值时,我的 jQuery 选择器出现此错误。
这是我用来遍历表格所有行的选择器:
for (var i = 0; i < myTable.rows.length; i++) {
var currentRow = $('#table-' + currentGraphOptions.id +' > tbody').children()[i];
var rowsHeight = currentRow.css('height');
}
标题上的错误是行高的结果。
这是完整的错误:
Uncaught TypeError: $(...).children(...)[0].css is not a function
at Scope.eval (eval at evaluate (unknown source), <anonymous>:1:65)
at Object.InjectedScript._evaluateOn (<anonymous>:905:55)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
at Object.InjectedScript.evaluateOnCallFrame (<anonymous>:964:21)
at Scope.controllers.controller.$scope.saveDashboard (http://localhost:9001/scripts/controllers/DashboardCtrl.js:497:61)
at $parseFunctionCall (http://localhost:9001/bower_components/angular/angular.js:12404:18)
at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:9001/bower_components/angular/angular.js:21566:17)
at Scope.$get.Scope.$eval (http://localhost:9001/bower_components/angular/angular.js:14466:28)
at Scope.$get.Scope.$apply (http://localhost:9001/bower_components/angular/angular.js:14565:23)
at HTMLAnchorElement.<anonymous> (http://localhost:9001/bower_components/angular/angular.js:21571:23)
最佳答案
这是因为您正在使用 DOM 节点而不是 jQuery 对象。请改用 .children().eq(i)
。
关于javascript - 未捕获的 TypeError : $(. ..).children(...)[0].css 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32136640/