Javascript 未在PhpStorm/WebStorm的类型节点中定义属性id
Php/WebStorm在我的JavaScript代码中报告此wierd警告,指出元素/节点中未定义属性Javascript 未在PhpStorm/WebStorm的类型节点中定义属性id,javascript,dom,phpstorm,webstorm,Javascript,Dom,Phpstorm,Webstorm,Php/WebStorm在我的JavaScript代码中报告此wierd警告,指出元素/节点中未定义属性id。事实上,元素是从父元素获取的第一个子元素 function hideChildAndUpdateID(title) { let parent = document.getElementById('parent'); let child = parent.firstChild; // Hiding the child. child.style.displa
id
。事实上,元素是从父元素获取的第一个子元素
function hideChildAndUpdateID(title) {
let parent = document.getElementById('parent');
let child = parent.firstChild;
// Hiding the child.
child.style.display = 'none';
// Temporary ID so we can find it later.
child.id = 'child-tmp-id'; // Warning occurs here
}
这是来自Php/WebStorm的全部消息
Property id is not defined in type Node less... (Ctrl+F1)
Inspection info: This inspection reports assignments to undefined properties of explicitly type-annotated variables.
这段代码本身实际上是有效的。child
元素将其id
更改为我设置的任何值,但此警告对我有影响
我尝试过使用child.setAttribute('id','child tmp id')
,但没有正常工作
处理firstChild
或它只是一个Php/WebStorm东西时是否有约定?节点可以不仅仅是元素,不一定有id
属性。尝试使用firstElementChild
返回元素的第一个子元素:
function hideChildAndUpdateID(title) {
let parent = document.getElementById('parent');
let child = parent.firstElementChild;
// Hiding the child.
child.style.display = 'none';
// Temporary ID so we can find it later.
child.id = 'child-tmp-id';
}
我同时使用了setAttributeNode
和createAttribute
,这也很管用,但这样更好。谢谢