JavaScript学习记录总结(十)——几个重要的BOM对象

本文详细介绍了JavaScript中关于窗口的各种操作,包括弹出框的使用、打开新窗口的方法、定时执行的功能以及页面位置和历史记录的管理。通过具体的代码示例展示了如何实现这些功能。

一、弹出框

<script type="text/javascript">
    window.onload=function(){
         window.alert("msg alert");
         var msg =window.prompt("prompt", "hello"); //msg hello  或者null
         
         alert(msg);
         var msg1=window.confirm("hahah");  //msg1  true  false;
         alert(msg1);
         
         //alert prompt  confirm
         
    };
</script>

 

二、open

<script type="text/javascript">

function openW(){
   //定义自己的外观
   window.open("window2.html","mypage","width=500,height=500,titlebar=yes,resizable=yes",true);
}
</script>
  </head>
  <body>
      <input type="button" onclick="openW()" value="打开新窗体"/>
  </body>

 

三、window.setInterval

<script type="text/javascript">
//window.self属性  代表当前的窗体
//window.setInterval("函数名()",时间戳); 每隔时间戳 执行一次函数
var id=window.self.setInterval("clock()",1);
function clock(){
  var t=new Date();
  document.getElementById("clock").value=t;
}
 
function cls(){
    window.self.clearInterval(id);
}
</script>
  </head>
 
<body>
<!-- 输入框 -->
<input type="text" id="clock" size="35" />
<input type="button" value="清空操作" onclick="cls()"/>
</body>

 

四、window.setTimeout

<script type="text/javascript">
//window.self属性  代表当前的窗体
//window.setTimeout("函数名()",时间戳); 隔时间戳后 执行一次函数
var id=window.self.setTimeout("clock()",3000);
function clock(){
  var t=new Date();
  document.getElementById("clock").value=t;
  //id=window.self.setTimeout("clock()",3000);
}
 
function cls(){
   window.clearTimeout(id);
}

//面试题
</script>
  </head>
 
<body>

<!-- 输入框 -->
<input type="text" id="clock" size="35" />

<input type="button" value="清空操作" onclick="cls()"/>

</body>

 

五、Location

<script type="text/javascript">
  function goUrl()
  {
    
       alert(window.location.host);
     alert(window.location.hostname);
     alert(window.location.port);
     alert(window.location.protocol);
     alert(window.location.search);
      window.location.href="http://www.baidu.com";
      
  }
</script>
  </head>
 
  <body>
     <input type="button" value="发送新的请求" onclick="goUrl()"/>
  </body>

 

六、History

1.html

  <body>
     <a href="2.html">进入2.html</a>
     
     <a href="./l.html?name=chj">进入l.html</a>
  </body>

2.html

   <body>
   <!--  <a href="javascript:history.back()">返回1.html</a> -->
    <a href="javascript:history.go(-1)">返回1.html</a>
    <a href="3.html">进入3.html</a>
    <!-- <a href="javascript:history.forward()">前进</a> -->
    <a href="javascript:history.go(1)">前进</a>
  </body>

3.html

  <body>
    This is my HTML page. <br>
    
   <!--  <a href="javascript:history.back()">返回2.html</a> -->
    <a href="javascript:history.go(-1)">返回12.html</a>
  </body>

 

转载于:https://www.cnblogs.com/ly-radiata/p/4425692.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值