87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type="text/javascript" src="F:\workspace\JavaDemo\js\jquery-1.4.3.js"></script>
<script type="text/javascript">
$(function(){
var timer;
$("td[name='two']").each(
function(i){
$(this).hover(
function (){
var obj =$(this);
//外面嵌套一个function,不做任何操作,setTimeout里放你自己的处理
timer=setTimeout(function(){obj.css({"backgroundColor":"red"});},2000);
},
function(){
if(timer) {
clearTimeout(timer);
$(this).css({"backgroundColor":""});
};
}
);
}
);
});
</script>
</head>
<body>
<table border="1">
<tr>
<td>aaaaaaaaaa</td><td name="two">bbbbbbbbb</td>
</tr>
<tr>
<td>cccccccccc</td><td name="two">ddddddddd</td>
</tr>
</table>
<body>
</html>
<html>
<head>
<script type="text/javascript" src="F:\workspace\JavaDemo\js\jquery-1.4.3.js"></script>
<script type="text/javascript">
$(function(){
var timer;
$("td[name='two']").each(
function(i){
$(this).hover(
function (){
timer=setTimeout(function(){timer = 0;alert("begin")},2000);
},
function(){
if(timer) {
clearTimeout(timer);
timer = 0;
return;
};
alert("end");
}
);
}
);
});
</script>
</head>
<body>
<table border="1">
<tr>
<td>aaaaaaaaaa</td><td name="two">bbbbbbbbb</td>
</tr>
<tr>
<td>cccccccccc</td><td name="two">ddddddddd</td>
</tr>
</table>
<body>
</html>
<!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" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var timeout = '';
$('p').mouseover(function(){
timeout = setTimeout(function(){
alert('2秒')
},2000);
})
$('p').mouseout(function(){
clearTimeout(timeout)
})
})
</script>
<style type="text/css">
</style>
</head>
<body>
<p>11111111111111111111111111</p>
</body>
</html>
$(function() {
var timer;
$("input:button").hover(function() {
var self = this;
timer = setTimeout(function() {
timer = 0;
$(self).css("color", "red");
}, 2000);
}, function() {
if (timer) {
clearTimeout(timer);
timer = 0;
return;
}
$(this).css("color", "");
});
});
<!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" xml:lang="zh">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
div{width:100px;height:100px;border:solid 1px red;}
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
var timer = null;
$(function(){
$("#test").hover(
function(){
$(this).html("悬停");
timer=setTimeout(function(){alert("hello")},2000);
},
function(){
if(timer)
clearTimeout(timer);
$(this).html("测试");
});
});
</script>
</head>
<body>
<div id="test">
测试
</div>
</body>
</html>
str = setInterval(function () {
//绑定out事件
clearInterval(str);
}, 2000);
<!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>无标题文档</title>
</head>
<body onload="init()">
<script language="javascript">
var
bIn = false,
oHint;
oTimer;
function init()
{
oHint = document.getElementById("hinter");
hideHint();
}
function onOut()
{
bIn = false;
clearTimeout(oTimer);
}
function onOver()
{
bIn = true;
oTimer = setTimeout("onTime()", 2000);
}
function onTime()
{
if(bIn)
{
oHint.style.display = "";
}
}
function hideHint()
{
oHint.style.display = "none";
}
</script>
<table border="1" cellpadding="6" cellspacing="0" onmouseover="onOver()" onmouseout="onOut()">
<tr>
<td><p>你敢在这<br />
区域里停<br />
两秒吗?</p></td>
</tr>
</table>
<div style="position:absolute; display:inline; background:#999" id="hinter" onclick="hideHint()">你赢了<br>[关闭]</div>
</body>
</html>