第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有 id 'notes' 的 div 不會在 javascript 代碼中顯示默認注釋

帶有 id 'notes' 的 div 不會在 javascript 代碼中顯示默認注釋

蕪湖不蕪 2021-11-25 16:12:08
默認文本應該顯示在帶有 id 'notes' 的 div 中。包含用于顯示注釋的按鈕的 Javascript 代碼。有條件顯示更新的注釋和默認文本。給出了在更新之前應該顯示的默認文本部分。但是,不顯示默認文本。我沒有發(fā)現(xiàn)任何錯誤。怎么做?<hr><h1>Your Notes:</h1><hr><!-- container-fluid use up all the available spaces --><div id="notes" class="row container-fluid"></div>function show_notes() {    let notes = localStorage.getItem("notes");    if (notes == null) {       notesObj = [];    }    else {        notesObj = JSON.parse(notes);    }    let html = "";    notesObj.forEach(function (element, index) {        //using backtick        html += `             <div class="noteCard my-2 mx-2 card" style="width: 18rem;">                    <div class="card-body">                        <h5 class="card-title">Note ${index + 1}</h5>                        <p class="card-text">${element}</p>                        <button href="#" class="btn btn-primary">Delete Note</button>                    </div>                </div>`;                  });               let notes_element = document.getElementById("notes");            if (notesObj.length != 0) {                notes_element.innerHTML = html;                //console.log("Add notes success!")            }            else {//default note                notes_element.innerHTML = `No note added. Use "Add Note" button to add a note.`;                //console.log('Notes not added!');            }        }
查看完整描述

2 回答

?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

如果notesObj被初始化為一個空數(shù)組,您forEach()將不會執(zhí)行并添加默認的筆記 HTML。


const test = [];


test.forEach(() => console.log("won't log"));


查看完整回答
反對 回復 2021-11-25
?
眼眸繁星

TA貢獻1873條經(jīng)驗 獲得超9個贊

非常感謝您的意見和解決方案。其實,我錯了。函數(shù) show_notes() 將在 .addEventListener 之前/之外和 .addEventListener 函數(shù)之內(nèi)/結束時調(diào)用。


查看完整回答
反對 回復 2021-11-25
  • 2 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號