uck typeerror:无法读取空的属性(读取'appendchild');持续错误
2022-03-23
1274
我的脚本标签位于我的身体标签的底部,这是我在此处找到的主要解决方案。是否还有其他原因附录会陷入此错误?
html:
606094027
javascript:
770045088
2个回答
当定位到类名时,需要在 querySelector() 中添加“.”
const aboutMeText = document.querySelector(".about-me-text");
const aboutMeTextContent = `I am a creative designer, who dabbles in both website
creation & digital art design. Contact me to start a creative project or website
today.`
Array.from(aboutMeTextContent).forEach(char => {
const span = document.createElement("span");
span.textContent = char;
aboutMeText.appendChild(span);
})
<section class="section-2">
<p class="about-me-text"></p>
</section>
Jscrip
2022-03-23
使用
querySelector
时,您必须明确选择哪个元素,例如,在您的问题中,当您选择一个类时,您必须在
about-me-text
的开头放置一个
.
。对于 ID,您将在开头添加一个
#
,等等。
const aboutMeText = document.querySelector(".about-me-text");
const aboutMeTextContent = 'I am a creative designer, who dabbles in both website creation & digital art design. Contact me to start a creative project or website today.'
Array.from(aboutMeTextContent).forEach(char => {
const span = document.createElement("span");
span.textContent = char;
aboutMeText.appendChild(span);
})
<section class="section-2">
<p class="about-me-text"></p>
</section>
<script src="rScript.js"></script>
</body>
Rani Giterman
2022-03-23