我正在尝试使用下面的代码通过 javascript 在另一个窗口中编辑列表项的 innerHTML。
function searchNameButton() //this function is called when the user clicks the search by name button.
{
name = document.getElementById("nmSearch").value;
window = window.open("search.html"); //opens a new window, can be accessed through this window variable
matchIndexes = [];
for (i = 0; i < pokemon.length; i++) //do the actual search here
{
if (pokemon[i][1].toLowerCase().includes(name.toLowerCase())) //converts to lowercase so that the search is case-insensitive
{
matchIndexes.push(i);
}
}
//now to populate the new page, similar to how it was done before
itemList = window.document.getElementsByClassName("pd");
console.log(matchIndexes);
for (i = 0; i < itemList.length; i++)
{
itemList[i].innerHTML = generateString(pokemon[matchIndexes[i]]);
}
}
但是,当新窗口打开时,没有任何改变。我确定 matchIndexes 正在工作,我输出了它的值,它在我的测试用例中找到了 3 个匹配项(应该如此),同样,当我将它输出到控制台时,itemList 正确填充了 20 个项目。但是,更改任何这些项目的 innterHTML,即使作为测试在 for 循环之外进行,也无济于事。我不确定我的错误到底是什么。
generateString() 函数,为了澄清,在其他地方工作正常,即使在最坏的情况下也不可能输出空字符串。至少它会输出一些我可以在检查器中看到的字符。
任何帮助,将不胜感激。
拉风的咖菲猫
相关分类