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

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

如何從js對象完全創(chuàng)建HTML?

如何從js對象完全創(chuàng)建HTML?

一只斗牛犬 2021-04-13 17:14:12
我正在努力尋找一種使用javascript為我的網(wǎng)站創(chuàng)建博客文章的方法。我精通javascript,但是除之外我沒有使用過許多DOM元素document.getElementById()。我正在尋求有關(guān)如何實現(xiàn)將JS對象轉(zhuǎn)換為帖子的方法的支持。這是一個示例對象:var posts = {     //My objectfirstPost: {      //An example post  index: 1,       //Identifies order of posts: 1 is oldest... >1 newest  id: "first", //An id for the post  date: {         //Date will be listed next to name on post    month: 11,    day: 2,    year: 2018  },  name: "My Post",              //Name of the post  text: "Text for the post...", //Actual Post  image: 'blogImage.png'        //An image for the post}現(xiàn)在,我想通過如下所示的函數(shù)傳遞它來創(chuàng)建HTML:function assemblePost( index, id, month, day, year, text, image) {   //DOM GOES IN HERE} 這是當(dāng)我手動鍵入HTML時HTML外觀的示例:<div class="card" id="first"> <!-- Card element links to css -->    <h2>My Post</h2> <!-- Name of the post -->    <h5>Posted November 2nd, 2018</h5> <!-- Date of the post -->    <div class="img" style="height:200px;"><img src="/blogImage.png" ></div>    <p>Text for the post..."</p> <!-- Actual Post --></div>我不確定如何處理此問題,因為:類“ card”鏈接到CSS,但我不確定如何使用DOM來實現(xiàn)。我不確定DOM是否可以編輯樣式,例如在此示例中,圖像高度為200,但是在另一幅圖像中,圖像高度可能有所不同。對于我的許多其他帖子,我可能有多個段落和/或列表。至少,我想要一種創(chuàng)建一個文本字符串的方法。也許對于列表而言,數(shù)組在我的對象中最有用,但是我不確定如何處理多個段落。我意識到這是很多解釋,示例和指南,但是,我非常感謝您的幫助!謝謝!
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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