Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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_Jquery_Html - Fatal编程技术网

Javascript 函数调用,延迟,然后再次调用函数

Javascript 函数调用,延迟,然后再次调用函数,javascript,jquery,html,Javascript,Jquery,Html,我正试图用两步函数编写一个代码来重写导航链接。我有删除链接的功能,然后是添加一组链接的功能,然后是另一个按钮做同样的事情,但有不同的链接。这就是我所拥有的。(包含1中的组件的HTML) function execFunction(){ 删除链接(); linksAddSet1(); } 函数execFunction2(){ 删除链接(); linksAddSet2(); } 函数removeLinks(){ var list=document.getElementById(“output2”)

我正试图用两步函数编写一个代码来重写导航链接。我有删除链接的功能,然后是添加一组链接的功能,然后是另一个按钮做同样的事情,但有不同的链接。这就是我所拥有的。(包含1中的组件的HTML)

function execFunction(){
删除链接();
linksAddSet1();
}
函数execFunction2(){
删除链接();
linksAddSet2();
}
函数removeLinks(){
var list=document.getElementById(“output2”);
list.removeChild(list.childNodes[0]);
list.removeChild(list.childNodes[0]);
list.removeChild(list.childNodes[0]);
list.removeChild(list.childNodes[0]);
list.removeChild(list.childNodes[0]);
list.removeChild(list.childNodes[0]);
}
函数linksAddSet1(){
var out=document.getElementById(“output2”);
var args=[“关于”、“游戏”、“藏身处”、“工作人员”、“捐赠”、“联系我们”];
功能显示菜单(){
var ul=document.createElement('ul');
ul.className=“主菜单”;
args.forEach(函数(名称、索引){
var li=document.createElement('li'),
an=document.createElement('a');
li.className=“mmenu项-”+索引;
li.setAttribute=“link rel”、“样式表”、“类型”、“文本/css”、“href”、“http://www.thegaminghideout.com/style.css";
an.innerHTML=名称;
.setAttribute('href',”http://www.thegaminghideout.com/“+name+”.html”);
李.儿童(安);;
ul.儿童(li);
});
儿童(ul);
}
如果(output2.childNodes.length>0){}else{
显示菜单();
}
}
函数linksAddSet2(){
var list=document.getElementById(“output2”);
var out=document.getElementById(“output2”);
var args=[“工具”、“教程”];
功能显示菜单(){
var ul=document.createElement('ul');
ul.className=“主菜单”;
args.forEach(函数(名称、索引){
var li=document.createElement('li'),
an=document.createElement('a');
li.className=“mmenu项-”+索引;
li.setAttribute=“link rel”、“样式表”、“类型”、“文本/css”、“href”、“http://www.thegaminghideout.com/style.css";
an.innerHTML=名称;
.setAttribute('href',”http://www.thegaminghideout.com/“+name+”.html”);
李.儿童(安);;
ul.儿童(li);
});
儿童(ul);
}
如果(output2.childNodes.length>0){}else{
显示菜单();
}
}
#导航{
宽度:760px;
高度:35px;
位置:绝对位置;
边框底部:2倍实心#000000;
背景:橙色;
填充:0px;
}
#导航。填充{
填充:2px;
}
#导航.导航链接{
位置:绝对位置;
顶部:1px;
左:0px;
}
#导航链接{
边际:0px;
填充:0px;
文本对齐:居中;
列表样式类型:无;
宽度:760px;
高度:35px;
}
#导航.导航链接{
位置:相对位置;
顶部:5px;
保证金:0px 5px 0px 5px;
列表样式类型:无;
显示:内联;
}
#导航。导航链接{
颜色:#000000;
填充:5px 0px 9px 0px;
文字装饰:无;
字号:18px;
字体系列:因果报应的拱廊规则;
填充:5px 0px 9px 0px;
}
#导航。导航链接a:悬停{
边际:0px;
颜色:#ffffff;
背景:橙色;
文字装饰:下划线;
}




删除链接 链接集1
链接集2
我认为您不需要延迟。按顺序执行时,您所尝试的是正常的。
removeLinks
函数中存在脚本错误。我已经把它修好了,它能正常工作。请参见

function removeLinks() {
    var list = document.getElementById("output2");
    //http://stackoverflow.com/a/683429/297641
    while (list.hasChildNodes()) {
        list.removeChild(list.lastChild);
    }
}
代码片段
function execFunction(){
删除链接();
linksAddSet1();
}
函数execFunction2(){
删除链接();
linksAddSet2();
}
函数removeLinks(){
var list=document.getElementById(“output2”);
while(list.hasChildNodes()){
list.removeChild(list.lastChild);
}
}
函数linksAddSet1(){
var out=document.getElementById(“output2”);
var args=[“关于”、“游戏”、“藏身处”、“工作人员”、“捐赠”、“联系我们”];
功能显示菜单(){
var ul=document.createElement('ul');
ul.className=“主菜单”;
args.forEach(函数(名称、索引){
var li=document.createElement('li'),
an=document.createElement('a');
li.className=“mmenu项-”+索引;
li.setAttribute=“link rel”、“样式表”、“类型”、“文本/css”、“href”、“http://www.thegaminghideout.com/style.css";
an.innerHTML=名称;
.setAttribute('href',”http://www.thegaminghideout.com/“+name+”.html”);
李.儿童(安);;
ul.儿童(li);
});
儿童(美国)