JS-window对象

来源:互联网 发布:广西南宁智尚网络骗局 编辑:程序博客网 时间:2024/05/22 16:00
JS对象 Date
 <body>
  <script>
var myDate=new Date();
myDate.setFullYear(2008,7,9); //设置日期为2008年8月9日(月份从0~11)
var today =new Date();
if(myDate>today)
{
alert("Today is before 9th August 2008");
}
else
{
alert("Today is after 9th August 2008");
}
  </script>
 </body>





JS window

window.screen:
screen.availWidth--可用的屏幕宽度
screen.availHeight--可用的屏幕高度

window location

location.href属性返回当前页面的URL
location.pathname属性返回URL的路径名
location.assign()方法加载新的文档
<script>
function newDoc()
{
  wondow.location.assign("http://www.w3school.com.cn");
}
</script>
<input type="button" value="加载文档" onclick="newDoc()">



JavaScript中可创建三种消息框:
警告框:alert("文本");
确认框:confirm("文本");
提示框:prompt("文本","默认值");




JavaScript计时事件
setTimeout() 未来的某时执行代码
clearTimeout()  取消setTimeout()

var t=setTimeout("javascript语句",毫秒);

<html>
<head>
  <script type="text/javascript">
  var c=0;
  var t;
  function timedCount()
  {
     document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
  }
  function stopCount()
  {
     clearTimeout(t);
  }
  </script>
  <body>
  <form>
   <input type="button" value="start count!" onclick="timedCount()"/>
   <input type="text" id="txt">
   <input type="button" value="stop count!" onclick="stopCount()">
  </form>

  </body>
</head>
</html>