简体   繁体   English

我无法在我的部分标签中获取我的 h3 标签和 p 标签?

[英]I am having trouble getting my h3 tags and p tags in my section tag?

I am reading data from a javascript file and then importing them into the HTML file.我正在从 javascript 文件中读取数据,然后将它们导入到 HTML 文件中。 The issue I am having is that I am unable to get my p tags and h3 tags in my section tag.我遇到的问题是我无法在我的部分标签中获取我的 p 标签和 h3 标签。 This is what it looks like when I load it up:这是我加载它时的样子:

点击这里

The following code is what I have tried.下面的代码是我试过的。 I have used inner HTML to create the tags and I am not sure what I can do to fix this.我已经使用内部 HTML 来创建标签,我不确定我能做些什么来解决这个问题。

// create a box class section for whole thing
containerElement.innerHTML += "<section class='flight-info'> ";

// another class for top part of box 
containerElement.innerHTML += "<div class='topBox' ";
// add all the elements such as destination and code
containerElement.innerHTML += "<h3 class='destination'> " + FlightInfo[i].destination + " </h3>";
containerElement.innerHTML += "<p class='departTime'> Depart time: " + FlightInfo[i].departTime + " </p>";


// have to check for # of stops to format. if its not 0, we can add the # of stops and time, otherwise its Non-stop, time
if (FlightInfo[i].stops != 0) {
  containerElement.innerHTML += "<p class='timeStop'>" + FlightInfo[i].stops + ", " + FlightInfo[i].time + " min </p>";
} else if (FlightInfo[i].stops == 0) {
  containerElement.innerHTML += "<p class='timeStop'> Non-Stop" + ", " + FlightInfo[i].time + " min </p>";
}

// end the topBox class
containerElement.innerHTML += "</div>"

containerElement.innerHTML += "</section>"

It's because you keep adding everything to the container.这是因为您不断将所有内容添加到容器中。

containerElement.innerHTML +=

You only need the code above one time (at least the way you're doing it now), and add everything in one long string.您只需要一次上面的代码(至少您现在这样做),然后将所有内容添加到一个长字符串中。

Otherwise, add the section, then select the section and add everything to the section's innerHTML.否则,添加该部分,然后 select 该部分并将所有内容添加到该部分的 innerHTML。 Same idea with the div.与 div 相同的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM