zoukankan      html  css  js  c++  java
  • javascript的内置对象

      javascript 基于浏览器,提供的内置对象,各个浏览器的支持不尽相同。

    • 图像对象

     

    • 导航对象

    • 窗口对象

    • 屏幕对象  screen

    <html> 
    <head> 
    <script type="text/javascript"> 
    with(document){ 
        writeln("实际高度:"+screen.availHeight+"<br>"); 
        writeln("实际宽度:"+screen.availWidth+"<br>"); 
        writeln("屏幕区域高度:"+screen.height+"<br>"); 
        writeln("屏幕区域宽度:"+screen.width+"<br>"); 
    } 
    </script> 
    </head> 
    </html>

     

    • 事件对象 event

    当事件发生时,由浏览器自动建立该对象,并包含该事件的类型、鼠标坐标等。

    在js中为某个对象(控件)绑定事件通常可以采取两种手段:

    1. <input type=”button” onclick=”clickHandler();”>
    2. <input type=”button” id=”button1”>

              <script type=”text/javascript”>

                 var v=document.getElementById(“button1”);

                  v.onclick=clickHandler;   //注意:这里不写括号

              </script>

    <html> 
    <body> 
    <input type="button" value="clickMe" id="button1">
    
    <script type="text/javascript"> 
    var v=document.getElementById("button1"); 
    function clickHandler(){ 
        alert("button1 is clicked"); 
    } 
    v.onclick=clickHandler; 
    </script> 
    </body> 
    </html>
      

     

    • 历史对象

    01.html

    <html>  
    <body> 
    <a href="02.html" >点击</a> 
    </body> 
    </html>

     

     

    02.html

    <html> 
    <body> 
    <a href="#" onclick="window.history.back(-1);return false;">返回</a> 
    </body> 
    </html>

    加return false;的原因是:执行完window.history.back(-1);后不去继续执行href

     

    • 位置对象--用来代表特定窗口的URL信息

    格式:

          location.属性

          location.方法(参数)

    5秒后前往另一url

    <html> 
    <head> 
    <script type="text/javascript"> 
        var timeId; 
        function loadPage(){ 
                timeId=setInterval("countDown();",1000); 
        } 
    </script> 
    </head>
    
    
    <body onload="loadPage();">
    
    <script type="text/javascript"> 
        var sec=5; 
        
        function countDown(){ 
            if(sec>0){ 
                document.getElementById("num").innerHTML=sec--; 
            }else{ 
                clearInterval(timeId); 
                location.href="http://www.baidu.com"; 
            } 
        } 
    </script> 
    5秒后前往<br> 
    <font id="num" size="7">5</font> 
    </body> 
    </html>
  • 相关阅读:
    MySQL性能优化
    性能测试结果分析
    TFS使用之代码管理
    新博开通,近期将推出系列博客之测试工具篇!
    绝对受用的TFS操作指南
    2008 &amp; 2005 TFS 安装心得及安装时遇到的问题!
    测试用例如何进行评审?
    cordova H5打包APK关键几点记录
    Silverlight+wcf 结合窗体验证演示
    两道js笔试题
  • 原文地址:https://www.cnblogs.com/qq-757617012/p/4185351.html
Copyright © 2011-2022 走看看