时间:2021-07-01 10:21:17 帮助过:7人阅读
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery防止click双击多次执行及传递动态函数方法</title>
<script type="text/javascript" src="http://www.86y.org/js/jquery.min.js"></script>
</head>
<body>
<div id="show">显示测试结果:</div>
<div style="background:#f60;color:#fff;width:80px;padding:10px 20px;" id="div" onclick="ss1('DIV事件')">点击我吧</div>
<input type="button" value="按钮一" id="but1" onclick="ss2('INPUT事件')"/>
<script language="javascript">
function std (obj,vs){
var TimeFn = null;
var funs=$(obj).attr("onclick");
$(obj).click(function() {
clearTimeout(TimeFn);
TimeFn = setTimeout(function(){
eval(funs);
clearTimeout(TimeFn);
}, 400);
});
$(obj).dblclick(function() {
clearTimeout(TimeFn);
});
$(obj).removeAttr("onclick");
}
var ss1=function(s){$("#show").html("DIV显示测试结果:"+s);alert("a");};//div调用的方法
var ss2=function(s){$("#show").html("INPUT显示测试结果:"+s);alert("b");};//input调用的方法
//通过方法动态绑定元素的事件
std("#div","div");
std("#but1","button1");
</script>
</body>
</html>