<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>函数延迟</title>
<script type="text/javascript" language="javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript" charset="utf-8">
function throttle(fn,delay){
var timer=null;
return function(){
var context=this;
args=arguments;
window.clearTimeout(timer);
timer=window.setTimeout(function(){fn.apply(context,args);},delay);
};
}
</script>
</head>
<body>
<script type="text/javascript" language="javascript" charset="utf-8">
$("body").keypress(throttle(function(event){alert("我会延迟执行");},3000));