ページ上のすべての selectBoxes の値をリセットしようとしています。問題のイベントは onClick で発生しているため、すべてが DOM に読み込まれます。
selectBoxes の HTMLCollection を取得しましたvar selectBoxes = document.getElementsByClassName("selectBox");
。これらの selectBoxes のそれぞれの selectIndex を 0 に変更したいと思います。
ただし、HTMLCollection から特定のオブジェクトのプロパティにアクセスしようとするたびに、未定義の値になってしまいます。
selectBoxes.item(0).selectedIndex = 未定義
selectBoxes[0].selectedIndex = 未定義
var selectBoxes = document.getElementsByClassName("filterBox");
console.log(selectBoxes); //a nice JavaScriptObject
for(i = 0; i < selectBoxes.length; i++){
selectBoxes.item(i).selectedIndex = 0;
}
これは HTMLCollections に関する非常に興味深い記事です: https://hackernoon.com/htmlcollection-nodelist-and-array-of-objects-da42737181f9これは、私の問題の一部を説明しているようです。