This article可能會幫助你。它使用這樣的技巧:
// executes an onchange function after 750ms (or specified delay)
function safeOnChange1(code, delay) {
delay = delay || 750;
window.clearTimeout(soc_id);
soc_id = window.setTimeout(code, delay);
}
// global timer ID for the safeOnChange1 function.
var soc_id = null;
這不是很漂亮,但這是在下拉菜單上使用onchange功能的問題。另一種解決方案是一個函數,每隔一段時間檢查下拉列表的值,如果更改,則調用onchange函數。
查找教程是這樣的:http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html
function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}
addEvent(window, 'load', foo);
addEvent(window, 'load', bar);
還有一個jQuery的方式,如果你可以看看它