javascript - Covid 19 跟踪器空代码。country_list_element.innerHTML += `
`;
问题描述
令人尴尬的是,我承认我是编程初学者,并且我正在为我的网站项目复制 youtube 教程中的代码,由于某些奇怪的原因,代码似乎为空,而搜索框上的国家/地区列表没有显示...我对如何配置它并几乎没有任何线索,我需要帮助:(
function createCountryList(){
const num_countries = country_list.length;
let i = 0, ul_list_id;
country_list.forEach( (country, index) => {
if( index % Math.ceil(num_countries/num_of_ul_lists) == 0){
ul_list_id = `list-${i}`;
country_list_element.innerHTML += `<ul id='${ul_list_id}'></ul>`;
i++;
}
document.getElementById(`${ul_list_id}`).innerHTML += `
<li onclick="fetchData('${country.name}')" id="${country.name}">
${country.name}
</li>
`;
})
}
let num_of_ul_lists = 3;
createCountryList();
// SHOW/HIDE THE COUTRY LIST ON CLICK EVENT
chang_country_btn.addEventListener("click", function(){
input.value = "";
resetCountryList();
search_country_element.classList.toggle("hide");
search_country_element.classList.add("fadeIn");
});
close_list_btn.addEventListener("click", function(){
search_country_element.classList.toggle("hide");
});
country_list_element.addEventListener("click", function(){
search_country_element.classList.toggle("hide");
});
// COUNTRY FILTER
/*input event fires up whenever the value of the input changes */
input.addEventListener("input", function(){
let value = input.value.toUpperCasse();
country_list.forEach( country => {
if( country.name.toUpperCase().startsWith(value)){
document.getElementById(country.name).classList.remove("hide");
}else{
document.getElementById(country.name).classList.add("hide");
}
})
})
// RESET COUNTRY LIST (SHOW ALL THE COUNTRIES )
function resetCountryList(){
country_list.forEach( country => {
document.getElementById(country.name).classList.remove("hide");
})
}```
解决方案
推荐阅读
- algorithm - 以下算法的运行时间是多少(就 - 表示法而言)?
- selenium - 我正在使用 selenium 抓取一个亚马逊网站作为产品链接但是得到了下面的错误
- javascript - 无法从变异的数组中渲染元素 - React
- javascript - 如何获得路径笔划的“轮廓”,并获得点以创建填充的路径形状?
- multidimensional-array - Google Analytics 中自定义维度中的自定义维度
- c - 如何通过C编程删除双链表中的节点?我做到了,但它返回分段错误。不知道哪一部分错了
- python-3.x - 我如何从列表中的多个 url 下载图像
- c# - HttpPostedFileBase 文件内容在使用一次后被删除 C# MVC
- java - 如何在 Java 8(Spring Boot)应用程序中设置最大非堆内存?
- r - 访问R中随机森林中每个元素的重要性