<!doctype html><html><head><meta charset="UTF-8"><title>Document</title><style type="text/css"> p{ width:150px; height:150px; float:left; border:1px solid #ddd; }</style></head><body><div id="append"> <p>amaze</p> <p>amaze</p> <p>amaze</p> <p>amaze</p></div><script type="text/javascript" src="jquery-3.1.1.min.js"></script><script type="text/javascript"> $("#append").on("mouseenter mouseleave","p",function(e){ if(e.type == "mouseenter"){ //鼠标进入 $(this).text("wow"); }else if(e.type == "mouseleave"){ //鼠标离开 $(this).text("amaze"); } });</script>
1 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
这应该是你想要的答案,重新优化了一下。
var timeoutObj = null; $("#append").on("mouseenter mouseleave","p",function(e){ if(e.type == "mouseenter"){ //鼠标进入 (function(me){ timeoutObj = setTimeout(function(){ $(me).text("wow"); },3000); }(this)); }else if(e.type == "mouseleave"){ //鼠标离开 $(this).text("amaze"); if(timeoutObj != null){ clearTimeout(timeoutObj); } } });
添加回答
举报
0/150
提交
取消