javascript - ReferenceError: $tableRows 未定义 jQuery
问题描述
我收到上述错误,但似乎找不到问题。我尝试了此处发布的各种解决方案,但仍然无法正常工作。
我对 jQuery 比较陌生。
$(document).ready(function(){
loadCalc.init();
var tableRows=$("#loadTable tbody tr");
$tableRows.each(function(index){
var $tableRow =jQuery(this);
})
$tableRow.find('.hours[]').on('change', function(){
var hrs=$tableRow.find("[name=hours[]]").val();
var qty=$tableRow.find("[name=quantity[]]").val();
var watts=$tableRow.find("[name=acwatts[]]").val();
var totalWatts=parseInt(hrs,10)*parseFloat(qty)*parseFloat(watts);
})
if (!isNaN(totalWatts)){
$tableRow.find('.total[]').val(totalWatts.toFixed(2));
var grandTotalWatts =0;
$(".totalWatts").each(function(){
var stVal = parseFloat($(this).val());
grandTotalWatts += isNaN(stVal)? 0 : stVal;
});
$('#totalSystem').val(grandTotalWatts.toFixed(2));
}
});
解决方案
即使您可以这样做,也不建议使用 JQuery 以 $ 为前缀命名变量!
在您的代码中,您已经初始化了tableRows变量,但没有使用 $ 作为前缀,但是在添加 $ ($tableRows) 之后使用它!
所以,你有两个选择:
- 编辑您的
var tableRows = ....
tovar tableRows = ...
或 - 替换你
$tableRows
的tableRows
推荐阅读
- convertapi - ConvertApi NuGet 包错误:无法安装包“ConvertApi 2.7.0”
- npgsql - 执行插入查询时出现异常,值中有一些特殊字符
- javascript - 使用 jQuery 为 Google reCaptcha v3 提交表单
- html - Angular 5 ngModel 更改 UI 中的值而不保存它
- coffeescript - 如何删除给定类的所有元素
- c# - 从 Unity 配置中获取当前域
- json - 从 JSON 响应中提取 OTP 值
- java - 由于某种原因,setText 没有改变 TextView 的任何内容
- excel - 将一列值排序到格式化的工作表中以打印标签
- ionic3 - 打开带有顶部滚动条的侧边菜单