gpt4 book ai didi

javascript - PhpStorm:未解析的变量readyState

转载 作者:行者123 更新时间:2023-12-03 03:49:24 26 4
gpt4 key购买 nike

我正在使用this code为了向我的所有表添加过滤字段。此过滤器使用 JavaScript 添加到我的导航栏。

  // Table filter.
// Source: https://codepen.io/chriscoyier/pen/tIuBL
(function(document) {
'use strict';

var LightTableFilter = (function(Arr) {

var _input;

function _onInputEvent(e) {
_input = e.target;
var tables = document.getElementsByClassName(_input.getAttribute('data-table'));
Arr.forEach.call(tables, function(table) {
Arr.forEach.call(table.tBodies, function(tbody) {
Arr.forEach.call(tbody.rows, _filter);
});
});
}

function _filter(row) {
var text = row.textContent.toLowerCase(), val = _input.value.toLowerCase();
row.style.display = text.indexOf(val) === -1 ? 'none' : 'table-row';
}

return {
init: function() {
var inputs = document.getElementsByClassName('light-table-filter');
Arr.forEach.call(inputs, function(input) {
input.oninput = _onInputEvent;
});
}
};
})(Array.prototype);

document.addEventListener('readystatechange', function() {
if (document.readyState === 'complete') {
LightTableFilter.init();
}
});

})(document);

代码本身完美运行。

但是,PhpStorm 向 document.readyState 添加了一条警告,指出它是一个未解析的变量

PhpStorm 是否缺少一些信息?我昨天下载并安装了它,所以它应该是最新版本。

<小时/>

我通过替换以下代码修复了它:

document.addEventListener('readystatechange', function() {
if (document.readyState === 'complete') {
LightTableFilter.init();
}
});

这样:

  document.addEventListener("DOMContentLoaded", function (event) {
LightTableFilter.init();
})

最佳答案

那么,为什么您认为 PhpStorm 会自动知道您的 document 变量是 document 的浏览器实例?你是对的,readyState 是浏览器内 document 的一个属性,但对于 PhpStrom 来说,它是未解析,因为它没有初始化。

关于javascript - PhpStorm:未解析的变量readyState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45231378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com