是什么導致以下問題?有什么想法嗎?謝謝。問題出在 clone = thead.cloneNode(true);
“Node”型別缺少“HTMLElement”型別的以下屬性:accessKey、accessKeyLabel、autocapitalize、dir 和 227 多個。
我也有問題Cannot read properties of null (reading 'getBoundingClientRect')
實際上我正在使用 Angular,但是我需要做一些自定義的事情,這就是我做這個手動 JS 事情的原因。
#代碼片段
let container = document.querySelector('#properties-content-left-container');
container.addEventListener("scroll", () => {
let filterChips = document.querySelector('#properties-filter-chips');
let filterChipsBB = filterChips.getBoundingClientRect();
let top = filterChipsBB.top filterChipsBB.height;
let table = document.querySelector('#table') as HTMLElement | null;
let tableBB = table.getBoundingClientRect();
let thead = table.querySelector('thead:not(.temporary)') as HTMLElement | null;;
let gridContainer = document.querySelector('.grid-container');
let clone = table.querySelector('thead.temporary') as HTMLElement | null;
table.style.position = 'relative';
if (tableBB.top < top) {
if (thead.style.position != 'fixed') {
thead.style.position = 'fixed';
thead.style.top = top 'px';
thead.style.width = (gridContainer ? gridContainer.clientWidth : table.clientWidth) 'px';
thead.style.maxWidth = (gridContainer ? gridContainer.clientWidth : table.clientWidth) 'px';
thead.style.overflowX = 'auto';
}
if (!clone) {
clone = thead.cloneNode(true);
clone.classList.add('temporary');
clone.style.opacity = '0';
clone.style.top = '0';
clone.style.position = 'sticky';
clone.style.width = 'auto';
clone.style.maxWidth = 'unset';
table.prepend(clone);
}
uj5u.com熱心網友回復:
對于第一個問題,使用型別斷言告訴編譯器該節點實際上是一個 HTMLElement
clone = thead.cloneNode(true) as HTMLElement
對于第二個問題,檢查是否filterChips為table空。為此使用除錯器/控制臺。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/495091.html
標籤:javascript 有角度的 打字稿
