首页 > 其他 > 详细

bom对象

时间:2019-02-22 10:58:24      阅读:197      评论:0      收藏:0      [点我收藏+]

1.prompt方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象二</title>
</head>
<body>
    <!-- 
        window窗口对象
        顶层对象(所用的bom对象都是在window里面操作的)
     -->
      <script type="text/javascript">
          //第一个参数是文本框提示,第二个参数是默认值
          var name = prompt("please enter your name","巫妖果子");
          document.write(name);
      </script>
</body>
</html>

技术分享图片

技术分享图片


2.open()方法

第一个参数是跳转地址的url,第三个地址是窗口特征

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象之open方法</title>
</head>
<body>
    <input type="button" value="open" onclick="open1()">
    <script type="text/javascript">
        //open()方法:打开一个新的窗口
          function open1(){
              open("https://www.baidu.com","","width=400,height=400");
          }
    </script>    
</body>
</html>

技术分享图片


3.close()方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象之open方法</title>
</head>
<body>
    <input type="button" value="open" onclick="open1()">
    <script type="text/javascript">
        //open()方法:打开一个新的窗口
          function open1(){
              open("https://www.baidu.com","","width=400,height=400");
          }
          //close()方法,关闭窗口
          window.close();
    </script>    
</body>
</html>

4.setInterval()方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象之setInterval方法</title>
</head>
<body>
    <script type="text/javascript">
     //间隔三秒弹出对话框
     //第一个参数传代码,第二个参数传计时时间
     setInterval("alert(‘123我爱你‘);",3000);
    </script>
</body>
</html>

技术分享图片


5.setTimeout()方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象之ettimeout方法</title>
</head>
<body>
    <script type="text/javascript">
    //setTimeout方法,第一个参数是js代码,第二个参数是时间间隔,且只重复一次
    setTimeout("alert(‘abc‘);",4000);
    </script>    
</body>
</html>

技术分享图片


6.清除计时

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bom对象之清除计时</title>
</head>
<body>
    <input type="button" value="Interval" onclick="Interval()">
    <input type="button" value="Timeout" onclick="Timeout()">
    <script type="text/javascript">
    var id1 = setInterval("alert(‘123我爱你‘);",3000);
    //var id2 = setTimeout("alert(‘abc‘);",4000);
    //clearInterval清除setInterval方法计时
    function Interval(){
        clearInterval(id1);
    }
    //clearTimeout清除setTimeout方法计时
    function Timeout(){
        clearTimeout(id2);
    }
    </script>
</body>
</html>

当点击相应按钮后,alert提示框不在重复出现

bom对象

原文:https://www.cnblogs.com/zjm1999/p/10416834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!