博客园  :: 首页  :: 管理

新手入门常用代码集锦(1)

Posted on 2006-01-24 10:33  Paker Liu  阅读(374)  评论(0编辑  收藏  举报
层的隐藏与显示

  只要设置style的display属性即可
  比如<div style="display:none" id="MyDiv">隐藏的层</div>
  如果要显示它可以通过脚本来控制
  window.document.getElementById("MyDiv").style.display = "";

禁止右键
  
  <body oncontextmenu="return false">

屏蔽页面中程序运行出错信息

  window.onerror = function()
  {
    return true;
  }

得到当前显示器的分辨率

  window.srceen.width 得到屏幕的宽度
  window.srceen.height 得到屏幕的高度
  如果当前分辨率为800*600,window.srceen.width是800,window.srceen.height是600

定时运行特定代码

  setTimeout(Code,Timeout);
  setInterval(Code,Timeout);
  Code是一段字符串,里边是js代码,Timeout是时间间隔,单位是微秒
  setTimeout是从现在算起多少微秒后运行该代码(只运行一次)
  setInterval是每隔多少微秒运行一次代码

得到本页网址

  var Url = window.location.href;

保存当前页面的内容

  document.execCommand("SaveAs","","C:\\index.htm");