它很簡單,我無法理解,是什麼問題? 所有DOM在我選擇它們之前創建,使用document.getElementsByClass或只是dom對象創建它自己,不工作......我想知道我在哪裏做錯了?.innerHTML不是函數
var wrapperDom = document.createElement('div');
wrapperDom.className = 'sticky-state-wrapper';
var containerDom = document.createElement('div');
containerDom.className = 'sticky-state-container';
var targetDom = document.createElement('div');
targetDom.className = 'sticky-state-target';
targetDom.style.height='50px';
targetDom.innerHTML("My Sticky Component");
https://jsfiddle.net/adamchenwei/cv3mpL4k/1/
嘛,'innerHTML'不是函數... https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML – elclanrs
應該是'targetDom .innerHTML =「我的粘滯組件」;' – avrahamcool
嘗試targetDom.innerHTML =「我的粘滯組件」; –