欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

javascript 延时和取消延时

程序员文章站 2022-06-25 18:25:47
...
方法一:

$("#notice").fadeIn(function() {
        setTimeout(function() {
            $("#notice").fadeOut();
        }, 3000);
    });

方法二:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="js/jquery-1.4.2.js"></script>
<script>
function show(){
   alert("show!!");
}

$(function(){
  $('#mydiv').mouseover(function(){
         t = setTimeout("show()",2000);
     }).mouseout(function(){
         clearTimeout(t);
   });
});
</script>
</head>

<body>
<span id="mydiv">我是菜单</span>
</body>