【发布时间】:2011-05-05 00:12:09
【问题描述】:
我已经声明了两个变量,COURSE_ID_List 和 COURSE_ID_timerId。然后将它们作为参数从 OnKeyUp 事件传递给 SetFilter 函数。
如果列表未定义,它应该初始化它。问题是列表始终未定义,因此我假设 OnKeyUp 事件中使用的 COURSE_ID_List 是按值传递的,而不是通过引用传递的。我该如何解决这个问题?
谢谢
<script type="text/javascript">
function SetFilter(ddl, value, list, timerId) {
if (list == undefined)
list = new ListFilter(ddl);
clearTimeout(timerId);
timerId = setTimeout(function() { list.SetFilter(value);}, 1500);
}
var COURSE_ID_List;
var COURSE_ID_List_timerId;
</script>
<input name="Course" type="text" id="COURSE_ID" onKeyUp="SetFilter('COURSE_ID', this.value, COURSE_ID_List, COURSE_ID_List_timerId);" />
【问题讨论】:
-
请注意,keyup 事件并不是检测用户输入的好方法。您可以使用其他事件来捕获其他类型的输入,例如粘贴或拖放。见whattheheadsaid.com/2010/09/…
标签: javascript pass-by-reference