我定义了一个' rtextDiv'作为它之后的两个eventListener函数的全局变量,但是firefox调试器告诉我在第二个eventListener函数中未定义rtextDiv。我错了吗?
以下是代码:
var rtextDiv;
// setup filter change event for the last added expression results
for (var i = 0; i < dmsg.getElementsByClassName('refilter').length; i++) {
var refilterInput = dmsg.getElementsByClassName('refilter')[i];
refilterInput.addEventListener('keyup', function () {
rtextDiv = refilterInput.parentNode.parentNode.getElementsByClassName('rtext')[0];
while (rtextDiv.firstChild) {
rtextDiv.removeChild(rtextDiv.firstChild);
}
fil1 = filteredPropertiesTable(res, refilterInput.value);
rtextDiv.appendChild(fil1);
});
}
for (var i = 0; i < dmsg.getElementsByClassName('propfilter').length; i++) {
var refilterInput2 = dmsg.getElementsByClassName('propfilter')[i];
refilterInput2.addEventListener('keyup', function () {
**while (rtextDiv.firstChild) {**
rtextDiv.removeChild(rtextDiv.firstChild);
}
rtextDiv.appendChild(filterTable(refilterInput2.value, fil1));
});
}