欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery 事件執(zhí)行檢測(cè)代碼

 更新時(shí)間:2009年12月09日 04:20:30   作者:  
在寫(xiě)Web 應(yīng)用,或者Web Ajax功能的時(shí)候我們經(jīng)常需要處理事件,jquery已經(jīng)非常完美的封裝了事件,但是有時(shí)候事件的執(zhí)行順序還是會(huì)有微小差別
前兩天做城市搜索的時(shí)候,我對(duì)搜索按鈕綁定了事件,如果輸入欄內(nèi)的文字不符合要求就用標(biāo)簽提示(標(biāo)簽展示出來(lái)后對(duì)document綁定click,點(diǎn)擊后隱藏標(biāo)簽)并使輸入欄獲得焦點(diǎn)。就這樣一個(gè)小功能我調(diào)試了、3個(gè)多小時(shí),IE 里表現(xiàn)的是標(biāo)簽一閃而過(guò),后來(lái)發(fā)現(xiàn)是按鈕的點(diǎn)擊事件和input的交替出發(fā)了多次,估計(jì)是事件回退發(fā)生的,用了preventDefault() 和 stopPropagation()兩個(gè)函數(shù)后修正了問(wèn)題。雖然問(wèn)題解決了,但是事件的執(zhí)行順序真是很難掌握呀,于是我做了個(gè)簡(jiǎn)單的事件監(jiān)測(cè)函數(shù),可以自動(dòng)記錄頁(yè)面事件觸發(fā),見(jiàn)如下代碼(首先肯定要引入jquery!...)
復(fù)制代碼 代碼如下:

//事件執(zhí)行監(jiān)測(cè)
function eventsMonitor(op){
var defaultSetting = {
eventsStr: "click focus blur",
splitStr: " ",
css:{
"border":"1px red solid",
"z-index":9000000,
"background":"white",
"position":"absolute",
width:400,
height:200,
"overflow-x":"hidden",
"overflow-y":"auto"
}
};
var ops = $.extend(true,defaultSetting,op);
$('<div id="DivForLogEvents"><div></div><div>').appendTo("body").css(ops.css);
var $infolog = $("#DivForLogEvents div:eq(0)");
$.each(ops.eventsStr.split(ops.splitStr),function(i,v){
if(v != 'resize')
$("*:not('#DivForLogEvents')").bind(v, function(e){
if(!$(e.target).is("#DivForLogEvents") && !$(e.target).is($infolog)){
$infolog.append((e.target.nodeName||" ") + "->" + (e.target.id||e.target.Name||" ") + " "+v+" event!<br>");
$("#DivForLogEvents:not(:animated)").animate({scrollTop:$infolog.height()},300);
}
});
else
$(window).bind('resize', function(e){
if(!$(e.target).is("#DivForLogEvents") && !$(e.target).is($infolog)){
$infolog.append((e.target.nodeName||" ") + "->" + (e.target.id||e.target.Name||" ") + " "+v+" event!<br>");
$("#DivForLogEvents:not(:animated)").animate({scrollTop:$infolog.height()},300);
}
});
});
}

調(diào)用方法示例
復(fù)制代碼 代碼如下:

<!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=utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><!--Google CDN-->
<script type="text/javascript" src="eventsMonitor.js"></script><!--Google CDN-->
<script type="text/javascript">

$(document).ready(function(){
eventsMonitor({
css:{top:0,right:20},
eventsStr:"click blur focus select scroll mousewheel resize"
});

$("#info").click(function(){$(this).text($("#DivForLogEvents").outerHeight());});
});

</script>
</head>
<body>

Hello world
<img src="/upload/2009-12/20091209042029557.gif" />
<input type="text" id="name" value="測(cè)試" />
<span id="info">ffffffff</span>
</body>
</html>

效果截圖

相關(guān)文章

最新評(píng)論