gpt4 book ai didi

javascript - 存储包含 html 标签的文本

转载 作者:行者123 更新时间:2023-11-28 05:55:07 24 4
gpt4 key购买 nike

我有要存储的字符串和对象。字符串中的一些文本需要特殊的格式,特别是必须是下标。我试过简单地编写 元素标签。标签在显示时显示在页面上。我创建了一个变量,保存了标签,将内容附加到变量,子元素无效。尝试将 .innerHTML 添加到变量中,仍然没有任何乐趣。任何想法。

var quizDiv = document.createElement("div")
//gives from element and id attribute
quizDiv.setAttribute("id", "airspeedIndicatorQuiz")
//retreives element on page inwhitch to place form and saves it in variable
var makeNewPage = document.getElementById("newPage")
//appentds input form to makeNewPage
makeNewPage.appendChild(quizDiv)

//creat sub element and store in variable vso
var vso = document.createElement("sub")
//creat text node and store in variable vsoText
var vsoText = document.createTextNode("SO")
//append vsoText to vso
vso.appendChild(vsoText)

console.log(vso)
var aIMakingsObj = [{
marking: "White arc",
meaning: "Flap oparating range"
}, {
marking: "V" + vso.innerHTML + " Lower A/S Limit White Arc",
meaning: "Stall speed landing configuration"
}, {
marking: "V<sub>FE</sub> Upper A/S Limit White Arc",
meaning: "Maximum flap extention speed"
}, {
marking: "Green Arc",
meaning: "Normal Oparating Range"
}, {
marking: "V" + '<sub>S1</sub>' + " Lower A/S Limit Green Arc",
meaning: "Maximum flap extention speed"
}, {
marking: "V<sub>NO</sub> Upper A/S Limit Green Arc",
meaning: "Maximum structural cruse speed"
}, {
marking: "Yellow Arc",
meaning: "Caution Range (oparations in smooth air only)"
}, {
marking: "V" + '<sub>NE</sub>' + " Red Line",
meaning: "never exceed speed; above this speed structural failure may occure"
}]

displayQuiz()

function displayQuiz() {


for (i = 0; i < aIMakingsObj.length; i++) {


var aPool = document.createElement("p")
var aPoolTex = document.createTextNode(aIMakingsObj[i].marking)
aPool.appendChild(aPoolTex)
makeNewPage.appendChild(aPool)
}
}
<!DOCTYPE html>
<html>

<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body id="newPage">




<script src="js/main.js"></script>
</body>

</html>

最佳答案

innerHTML 似乎在工作。

var quizDiv = document.createElement("div")
//gives from element and id attribute
quizDiv.setAttribute("id", "airspeedIndicatorQuiz")
//retreives element on page inwhitch to place form and saves it in variable
var makeNewPage = document.getElementById("newPage")
//appentds input form to makeNewPage
makeNewPage.appendChild(quizDiv)

//creat sub element and store in variable vso
var vso = document.createElement("sub")
//creat text node and store in variable vsoText
var vsoText = document.createTextNode("SO")
//append vsoText to vso
vso.appendChild(vsoText)

console.log(vso)
var aIMakingsObj = [{
marking: "White arc",
meaning: "Flap oparating range"
}, {
marking: "V" + vso.innerHTML + " Lower A/S Limit White Arc",
meaning: "Stall speed landing configuration"
}, {
marking: "V<sub>FE</sub> Upper A/S Limit White Arc",
meaning: "Maximum flap extention speed"
}, {
marking: "Green Arc",
meaning: "Normal Oparating Range"
}, {
marking: "V" + '<sub>S1</sub>' + " Lower A/S Limit Green Arc",
meaning: "Maximum flap extention speed"
}, {
marking: "V<sub>NO</sub> Upper A/S Limit Green Arc",
meaning: "Maximum structural cruse speed"
}, {
marking: "Yellow Arc",
meaning: "Caution Range (oparations in smooth air only)"
}, {
marking: "V" + '<sub>NE</sub>' + " Red Line",
meaning: "never exceed speed; above this speed structural failure may occure"
}]

displayQuiz()

function displayQuiz() {


for (i = 0; i < aIMakingsObj.length; i++) {
var aPool = document.createElement("p");
aPool.innerHTML = aIMakingsObj[i].marking; // modified
makeNewPage.appendChild(aPool)
}
}
<!DOCTYPE html>
<html>

<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body id="newPage">




<script src="js/main.js"></script>
</body>

</html>

关于javascript - 存储包含 html 标签的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37108810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com