----------------------對于動(dòng)態(tài)的標(biāo)簽綁定事件------------------------
復(fù)制代碼 代碼如下:
var outTimer;//執(zhí)行時(shí)間
var upTimer;//執(zhí)行時(shí)間
var sqDiv = $("#tm");//要顯示的div
var test="";//標(biāo)識(shí),為了將鼠標(biāo)移到顯示的div上時(shí),div不會(huì)消失
var dd = "";//劃過某一字段傳的值
function test1(){
$("#tm").empty();//現(xiàn)將div清空
$.ajax({ //往里加數(shù)據(jù)
type:"post",
url:"<%=path %>/webmodule/constructionDecision/BaseCD/getCommunityInfo.do?stCode="+dd,
dataType:"json",
async:false,
success:function(data){
var td="";
for(var i=0;i<data.length;i++){
td+="<a id ='"+data[i].gridNumber+"'>"+data[i].name+"</a>";
}
$("#tm").append(td);
}
});
$("#tm").show();
}
function test2(){//隱藏div的方法
if(test ==""){
$("#tm").hide();
}
}
$("#cityTable a").die().live('mouseover mouseout', function(event) { //給動(dòng)態(tài)標(biāo)簽綁定事件
if(event.type=='mouseover'){ //移上時(shí)
clearTimeout(outTimer);//先清空移出的時(shí)間,這樣能避免鼠標(biāo)劃過就執(zhí)行函數(shù),減輕服務(wù)器的壓力
dd=$(this).attr("id");
upTimer = setTimeout(test1, 500);//0.5秒后再執(zhí)行
}
if(event.type=='mouseout'){
sqDiv.hover(
function(){
test = "on";//說明鼠標(biāo)在顯示的div上
},function(){
test = "";
test2();
});
clearTimeout(upTimer);
outTimer = setTimeout(test2, 500);
}
});
復(fù)制代碼 代碼如下:
//hoverDuring 鼠標(biāo)經(jīng)過的延時(shí)時(shí)間
//outDuring 鼠標(biāo)移出的延時(shí)時(shí)間
//hoverEvent 鼠標(biāo)經(jīng)過執(zhí)行的方法
//outEvent 鼠標(biāo)移出執(zhí)行的方法
$( function() {
$.fn.hoverDelay = function(options) {
var defaults = {
hoverDuring :200,
outDuring :200,
hoverEvent : function() {
$.noop();
},
outEvent : function() {
$.noop();
}
};
var sets = $.extend(defaults, options || {});
var hoverTimer, outTimer;
return $(this).each( function() {
$(this).hover( function() {
clearTimeout(outTimer);
hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
}, function() {
clearTimeout(hoverTimer);
outTimer = setTimeout(sets.outEvent, sets.outDuring);
});
});
}
復(fù)制代碼 代碼如下:
//$("#sosoFod h3").each( function() {
$("#sosoweb").each( function() {
var test = "";//當(dāng)test為空時(shí),鼠標(biāo)移到字段顯示div,移出隱藏div
var that = $(this);
var id = that.attr("id");
var div = $("#tm");
div.css("position", "absolute");//讓這個(gè)層可以絕對定位
that.hoverDelay( {
outDuring :1000,
hoverEvent : function() {
div.css("display", "block");
var p = that.position(); //獲取這個(gè)元素的left和top
var x = p.left + that.width();//獲取這個(gè)浮動(dòng)層的left
var docWidth = $(document).width();//獲取網(wǎng)頁的寬
if (x > docWidth - div.width() - 20) {
x = p.left - div.width();
}
div.css("left", x);
div.css("top", p.top);
//$("#tm").show();
},
outEvent : function() {
$("#tm").hoverDelay( {
outDuring :1000,
hoverEvent : function() {
test = "on";
$("#tm").show();
},
outEvent : function() {
test="";
$("#tm").hide();
}
});
if(test==""){
$("#tm").hide();
}
}
});
});
新聞熱點(diǎn)
疑難解答
圖片精選