• js-浏览器DOM


    1.window尺寸

    适配所有浏览器的尺寸方案

    var w=window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;
    var h=window.innerHeight
    || document.documentElement.clientHeight
    || document.body.clientHeight;

    2.window打开关闭窗口

    window.open("index01.html","name","width = 300, height = 300,left = 200,top = 200");

    window.close();关闭自己

    3.计时器setInterval和clearInterval定时执行

    var mytime = setInterval(function(){
      getTime();
    },1000);
    function getTime(){
      var d = new Date();
      var t = d.toLocaleTimeString();
      document.getElementById("ptime").innerHTML = t;
    }
    function stopTime(){
      clearInterval(mytime);
    }

    4.计时器setTimeout延时执行

    var myVar;
    function myFunction()
    {
      myVar=setTimeout(function(){alert("Hello")},3000);自己调自己可以循环

    }

    function myStopFunction()

    {
      clearTimeout(myVar);
    }

    5.History

    history.back() - 与在浏览器点击后退按钮相同

    history.forward() - 与在浏览器中点击按钮向前相同

    history.go() - 跳到某个

    6.Location

    location.href 属性返回当前页面的 URL。

    location.hostname 返回 web 主机的域名

    location.pathname 返回当前页面的路径和文件名

    location.port 返回 web 主机的端口 (80 或 443)

    location.protocol 返回所使用的 web 协议(http:// 或 https://)

    location.assign() 方法加载新的文档。

    7.Screen

    screen.availWidth - 可用的屏幕宽度

    screen.availHeight - 可用的屏幕高度

    8.弹窗

    弹窗使用 反斜杠 + "n"( ) 来设置换行。

    ---警告框

    alert();

    ---确认框

    var r=confirm("按下按钮");

    if (r==true){x="你按下了"确定"按钮!";}

    else{x="你按下了"取消"按钮!";}

    ---提示框

    window.prompt("sometext","defaultvalue");

  • 相关阅读:
    数据库学习笔记5---MySQL字符串函数、日期时间函数
    关于hibernate的AnnotationConfiguration的问题
    浅谈Java web 中request的setAttribute()用法
    JAVA常见面试题之Forward和Redirect的区别
    JSP页面中<%!%>与<%%>与<%=%>
    Servlet的生命周期
    JavaEE学习路线图
    java web项目WEB-INF与META-INF的作用
    iOS-申请邓白氏编码的超详细流程介绍
    从高版本JDK换成低版本JDK报错
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5981747.html
Copyright © 2020-2023  润新知