Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复此导航栏JavaScript代码?_Javascript - Fatal编程技术网

如何修复此导航栏JavaScript代码?

如何修复此导航栏JavaScript代码?,javascript,Javascript,我尝试使用这个JavaScript代码片段在网页中创建一个导航栏 sections.forEach((元素,索引)=>{ 设textlink=elem.getAttribute(“数据导航”); 让textnode=document.createTextNode(textlink); 让newli=document.createElement(“li”); 让newlink=document.createElement(“a”); appendChild(textnode); newli.app

我尝试使用这个JavaScript代码片段在网页中创建一个导航栏

sections.forEach((元素,索引)=>{
设textlink=elem.getAttribute(“数据导航”);
让textnode=document.createTextNode(textlink);
让newli=document.createElement(“li”);
让newlink=document.createElement(“a”);
appendChild(textnode);
newli.appendChild(newlink);
newlink.addEventListener(“单击”,()=>{
元素滚动视图({
行为:“平稳”
});
})
片段。追加子片段(newli);
})
附属物(片段);
但导航栏从未出现过。。。我试图在代码中不包含锚元素,并将锚元素放在列表元素之后,并尝试使用
let
const
而不是
var
,但仍然没有用。
有什么帮助吗?

您需要知道
部分
片段
,以及
myul
所指的内容。下面是一个适用于所提供脚本的示例HTML标记。这里有一些CSS,展示了一些flex box

const sections=document.queryselectoral('section');
const fragment=document.createDocumentFragment();
const myul=document.querySelector('.nav');
节。forEach((元素,索引)=>{
设textlink=elem.getAttribute(“数据导航”);
让textnode=document.createTextNode(textlink);
让newli=document.createElement(“li”);
让newlink=document.createElement(“a”);
appendChild(textnode);
newli.appendChild(newlink);
newlink.addEventListener(“单击”,()=>{
元素滚动视图({
行为:“平稳”
});
})
片段。追加子片段(newli);
})
附属物(片段);
//Ipsum
document.querySelectorAll('.ipsum').forEach(p=>
取('https://baconipsum.com/api/?type=meat-和填充词')
.then(response=>response.json())
.then(parages=>p.innerHTML=parages.map(p=>`${p}

`).join('')
html,
身体{
保证金:0;
填充:0;
}
标题{
字号:1.33em;
字体大小:粗体;
保证金:0.33em;
文本对齐:居中;
}
主要{
填充:0.5em;
}
.导航{
显示器:flex;
弯曲方向:行;
证明内容:中心;
列表样式类型:无;
保证金:0;
填充:0;
背景:浅灰色;
}
李国荣先生{
边缘:0.5em 1米;
填充:0;
光标:指针;
}
李海军:悬停{
文字装饰:下划线;
}
我的网站
    主要的 关于我们 帮助
    请包含更多上下文请检查控制台浏览器中是否有任何错误详细信息。如果是,请回答您的问题并添加错误详细信息。
    fragment
    在哪里定义?