windows对象及其案例

<!DOCTYPE html>
<html>
  <head>
    <title>windows对象</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
        <script type="text/javascript">
            function f1(){
                //打开一个新窗口
                var win=window.open("cal.html","登陆","width=400px,height=300px");
                setTimeout(function(){
                    win.close();
                },5000);
            }
            //确认框
            function f2(){
                //点击确认,返回值为true,否则为false
                var flag=confirm("确认吗");
                if(flag){
                    alert("你选择了确认");
                }else{
                    alert("你选择了取消 ");
                }
            }
            
            function f3(){
                var msg=prompt("请输入手机号:");
                alert(msg);
            }
            
            function f4(url){
                setTimeout(function(){
                location.href=url;
            },2000);
            }
        </script>

  </head>
  <body style="font-size:30px;">
    <input type="button" value="打开窗口" onclick="f1()"/>
    <input type="button" value="确认窗口" onclick="f2()"/>
    <a href="deldo" onclick="return confirm('你确定删除吗')">删除</a>
    <input type="button" value="提示窗口" onclick="f3()"/>
  </br>
  <input type="button" value="跳转到login" onclick="location.href='login.html'"/>
  <input type="button" value="跳转到QQ" onclick="f4('http://www.qq.com')"/>
   
  </body>
</html>

计时器案例

<!DOCTYPE html>
<html>
  <head>
    <title>动态时钟</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
        <style type="text/css">
            #p2{
                border:1px solid red;
                width:100px;
                text-align:center;
            }
            .show{
                display:block;
            }
            .hide{
                display:none;
            }
        </style>
        <script type="text/javascript">
            var timer;
            var is_start=false;//是否启动
            function start(){
                if(is_start){
                    return;
                }
                is_start=true;//控制一秒内多次点击
                timer=setInterval(function(){
                    var now=new Date();
                    var time=now.toLocaleDateString()+""+now.toLocaleTimeString();
                    var c=document.getElementById("p1");
                    c.innerHTML=time
                },1000)
            }
            
            function stop(){
                //如果已经暂停了就不需要暂停了
                if(!is_start){
                    return;
                }
                clearInterval(timer);
                is_start=false;
            }
            
            function del(){
                //删除数据给予提示,2秒后提示消失
                var p=document.getElementById("p2");
                p.className="show";
                //2秒后关闭
                setTimeout(function (){
                    p.className="hide";
                },2000)
            }
        </script>
  </head>
  
  <body>
    <input type="button" value="启动" onclick="start();"/>
    <button onclick="stop();">暂停</button>
    <p id="p1"></p>
    <hr/>
    <button onclick="del();">删除</button>
    <p id="p2" class="hide"> 操作成功</p>
  </body>
</html>

图片滚动按钮

<!DOCTYPE html>
<html>
  <head>
    <title>img_rol.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    
    <style type="text/css">
        .show{
            display:block;
        }
        .hide{
            display:none;
        }
        ul{
            width:480px;
            height:360px;
            list-style-type:none;
            padding:0px;
        }
    </style>
    
    <script type="text/javascript">
        var id ;
        var count=0;//计数器
        //开始循环轮播
        function start(){
            id=setInterval(function (){
                var ul=document.getElementById("photos");
                var lis=ul.getElementsByTagName("li");
                for(var i=0; i<lis.length;i++){
                    lis[i].className="hide";
                }
                //找到要显示的li,并且显示
                var index=count%lis.length;
                lis[index].className="show";
                count++;
            },1000);
        }
        
        //停止图片轮播
        function stop(){
            clearInterval(id);
        }
    </script>
  </head>
  
  <body>
  <!-- onmousemove鼠标悬停事件,onmouseout鼠标撤出事件 -->
    <ul id="photos" onmousemove="stop();" onmouseout="start();">
        <li class="show"> <img src="../images/f1.jpg"></li>
        <li class="hide"> <img src="../images/f2.jpg"></li>
        <li class="hide"> <img src="../images/f3.jpg"></li>
        <li class="hide"> <img src="../images/f4.jpg"></li>
    </ul>
  </body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 内容抽屉菜单ListViewWebViewSwitchButton按钮点赞按钮进度条TabLayout图标下拉刷新...
    皇小弟阅读 46,914评论 22 665
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,261评论 4 61
  • 我在2014年9月进入大学,学习环境设计。 这个暑假在某室内装饰公司实习,规模不大,可以说是小,公司差不多一半的人...
    皮球君阅读 515评论 4 7
  • cocoapods 安装挺简单,但是每次配置开发环境时,还得搜索安装方法挺费劲儿,所以自己简单做下笔记,为以后方便...
    WSJay阅读 632评论 0 0
  • 隔着二十七年的跌宕岁月,丰子恺用文字讲述了他的老师李叔同,谦谦君子的神态翩然于书中,使人强烈感受到这位老师的可敬、...
    清水无暇阅读 299评论 0 0