[英]can you guys help me with the order for the dom?
I have a problem with undefined property I added the first part of my js I have a document.readystate witch suppose to help with the Dom not reading fills but I still get undefined我有未定义属性的问题我添加了我的 js 的第一部分我有一个 document.readystate 女巫想帮助 Dom 不读取填充但我仍然未定义
if (document.readyState == `loading`) { document.addEventListener(`DOMContentLoaded`, ready); } else { ready } function ready() { var hiddentwo = document.getElementById(`sectiontop`) var hidden = document.getElementById(`sectionone`) var hiddentwo = document.getElementById(`sectiontop`) console.log(hiddentwo) const openModal = function() { hidden.classList.remove(`hidesection`); }; const closeModal = function() { hidden.classList.add('hidden'); }; const closeModal1 = function() { hiddentwo.classlist.remove(`hidesection1`) }; const closeModal11 = function() { hiddentwo.classlist.add(`hidesection1`) }; window.onload = function() { hiddentwo.classlist.remove('hidesection1') }; };
.hidesection1 { display: none; }
<section id="sectiontop" class="hidesection1">
Remove this block in your code:在您的代码中删除此块:
if (document.readyState == `loading`)
{document.addEventListener(`DOMContentLoaded`,ready);}
else{ready}
and replace it with either并将其替换为
document.addEventListener(`DOMContentLoaded`, ready);
or use the ready state change event (which requires checking the state inside your ready
function):或使用准备好的 state更改事件(这需要检查ready
函数中的 state):
document.addEventListener(`readystatechange`, ready);
// and in ready():
function ready() {
if (document.readyState === 'interactive') {
// your code from ready function body here
}
};
You always use either method, never both.你总是使用任何一种方法,从不同时使用。
as @Sebastian Simon and @ conexo pointed out hiddentwo.classlist.remove
must be hiddentwo.classList.remove.
正如@Sebastian Simon 和@conexo 指出的hiddentwo.classlist.remove
必须是hiddentwo.classList.remove.
Case matters in Javascript. Javascript 中的案例很重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.