Web API Document All In One
Web API Document All In One
document
document;
https://developer.mozilla.org/en-US/docs/Web/API/Document
document.all ❌
已弃用
typeof document.all
// 'undefined'
document.all;
https://developer.mozilla.org/en-US/docs/Web/API/Document/all
TypeScript
HTMLElement
/ HTMLCollectionOf / NodeListOf
// const dom = document.querySelector(selector);
// const dom: Element | null
// ❌
// const dom = document.querySelector(selector) as Element;
// ✅
// const dom = document.querySelector<HTMLElement>(selector);
// ✅
// const dom = <HTMLElement>document.querySelector(selector);
// ✅
const dom = document.querySelector(selector) as HTMLElement;
// console.log('\nbackground =', background);
// console.log('\ndom =', dom);
if (dom) {
dom.style.background = background;
}
// ✅
const doms = document.querySelectorAll(selector) as NodeListOf<HTMLElement>;
// ✅
// const doms = document.querySelectorAll(selector) as HTMLCollectionOf<HTMLElement>;
// ❌
// const doms = (NodeList<HTMLElement>)document.querySelectorAll(selector);
// ❌
// const doms = (HTMLCollection<HTMLElement>)document.querySelectorAll(selector);
if (doms) {
doms[0].style.background = background;
}
https://www.typescriptlang.org/docs/handbook/dom-manipulation.html
https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16198133.html
未经授权禁止转载,违者必究!