我正在爲我的學校開發這個webapp。該頁面應該通過url參數「class」過濾條目。這工作正常,據我所知,但當我嘗試更改過濾器時,它給「TypeError:對象不是一個函數」。我究竟做錯了什麼? TypeError:對象不是函數
<html>
<head>
<TITLE>Cancelled lessons</TITLE>
</head>
<body>
<script>
function filter(text){
text = text.toLowerCase();
for (i=0;i<lessonList.length;i++){
if(lessonList[i].innerHTML.toLowerCase().indexOf(text)==-1){
lessonList[i].style.display = "none";
}
else{
lessonList[i].style.display ="";
}
}
}
function gup(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return results[1];
}
</script>
<form>
Filter: <input type="text" id="filter" oninput="filter(document.getElementById('filter'))"/>
</form>
<div id="lessons">
<div class="entry"> MaA 11:00 C131 Ej NV3C</div>
</div>
<script>
var lessonList = document.getElementsByClassName("entry");
var filterField =document.getElementById("filter");
filterField.value = gup("class");
filter(filterField.value);
</script>
</body>
</html>
[oninput](http://msdn.microsoft.com/en -us/library/gg592978%28v = vs.85%29.aspx)是html5,在IE <9中不受支持,並且有一些[問題](http://blog.danielfriesen.name/2010/02/16/ html5-browser-maze-oninput-support /) - onkeypress或onkeyup怎麼樣? – mplungjan 2011-05-11 05:28:38
怎麼了'text = text.toLowerCase();'如果在這種情況下,'text'是一個參數,其值是一個'object' document.getElementById('filter')''你通過'filter(document。的getElementById( '過濾器'))'? – tradyblix 2011-05-11 05:36:31
錯誤在我這邊,它的意思是要通過filter.value(現在改爲filterfield.value) – remuladgryta 2011-05-11 08:36:13