js输入文本时判断是否停留3秒

JavaScript019

js输入文本时判断是否停留3秒,第1张

<script src="jquery.js"></script>

<input type="text" id="in" />

<script>

var sto

jQuery("#in").keyup(function(){

try{ clearTimeout(sto)}catch(e) {}

sto=setTimeout(myFun,3000)

}).blur(function(){

try{ clearTimeout(sto)}catch(e) {}

})

function myFun(){

alert("停留3秒了")

}

</script>

<html>

<head>

<script type="text/javascript" src="jq/jquery.js"></script>

</head>

<script type="text/javascript">

$(function() {

$("#div").mouseout(function(){

setTimeout(function(){$("#div2").hide()}, 3000)

})

})

</script>

<body>

<input type="text" value="div" id="div">

<div id="div2">

鼠标离开div,等待3秒钟后此段隐藏

</div>

</body>

</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

</head>

<style type="text/css">

.main{width:500pxheight:400pxborder:dashed 1px #cccmargin:0 autoline-height:400pxtext-align:center}

</style>

<body>

<script type="text/javascript">

$(function(){

$(".main").mouseover(function(){

setTimeout(function(){

alert('当你的鼠标移动到框体时,我会延迟3秒才显示哦!')

},3000)

})

})

</script>

<div class="main">把鼠标移入此框体中,等待3秒。</div>

</body>

</html>