Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.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_Drop Down Menu - Fatal编程技术网

Javascript 空不是一个函数

Javascript 空不是一个函数,javascript,jquery,drop-down-menu,Javascript,Jquery,Drop Down Menu,我很难找到删除列表中所有子项的代码中的错误: document.getElementById('btnGetExistingFiles')。onclick=function(){ var ul=document.getElementById('listExisting'); //我们将文件拆分成一个数组 var existingFiles=“a.yml b.yml c.yml d.yml”。拆分(“”); //如果列表中已经包含一些值,我们将删除它们 if(ul.hasChildNodes()

我很难找到删除列表中所有子项的代码中的错误:

document.getElementById('btnGetExistingFiles')。onclick=function(){
var ul=document.getElementById('listExisting');
//我们将文件拆分成一个数组
var existingFiles=“a.yml b.yml c.yml d.yml”。拆分(“”);
//如果列表中已经包含一些值,我们将删除它们
if(ul.hasChildNodes()){
ul.empty();
}
//对于每个文件,我们在列表中添加一个元素
existingFiles.forEach(函数(文件名){
log(“添加文件”);
var li=document.createElement(“li”);
var a=document.createElement(“a”);
a、 setAttribute(“href”、“#”);
a、 setAttribute(“类”、“现有文件”);
a、 appendChild(document.createTextNode(文件名))
李.儿童(a);
ul.儿童(li);
});
}

下拉示例

没有Element.prototype.empty属性。 但是jquery中有一个:

$(ul).empty();
While是一个jquery函数。。我认为您需要使用
ul.innerHTML=''而不是
ul.empty()

document.getElementById('btnGetExistingFiles')。onclick=function(){
var ul=document.getElementById('listExisting');
//我们将文件拆分成一个数组
var existingFiles=“a.yml b.yml c.yml d.yml”。拆分(“”);
//如果列表中已经包含一些值,我们将删除它们
if(ul.hasChildNodes()){
ul.innerHTML='';
}
//对于每个文件,我们在列表中添加一个元素
existingFiles.forEach(函数(文件名){
log(“添加文件”);
var li=document.createElement(“li”);
var a=document.createElement(“a”);
a、 setAttribute(“href”、“#”);
a、 setAttribute(“类”、“现有文件”);
a、 appendChild(document.createTextNode(文件名))
李.儿童(a);
ul.儿童(li);
});
}

下拉示例

Javascript没有
empty()
方法。您可能会对jQuery感到困惑。如果要使用jQuery方法,则需要将
ul
转换为jQuery对象:
$(ul).empty()
为什么嵌入jquery而不使用它?在
JavaScript
中,应该使用
ul.innerHTML=''。哦,是的,我没有用JQuery获取元素,我会修复它的。谢谢你的帮助answer@Jerome不客气。。祝你今天愉快:-)