一分心灵的宁静

在滚滚红尘,繁杂人世里,能够保持一分心灵的宁静,随时回到自己的内心深处,细细品味生命的奥妙,无疑是一种修身养性的人生境界

导航

从头开始学JavaScript

Posted on 2006-05-19 13:20  有缘无份  阅读(283)  评论(0)    收藏  举报
document.write("这是以 JavaScript 印出的!")     //显示在页面上
alert("嗨! 你好");     //弹出窗口

<a href="tpage.htm" onMouseOver="window.status='你好'; return true">  // 状态 出 现
//因为mouse 的指标已从 link 移开了,但是 statusbar 中的文字还留在那 ,以下是解决的办法

 setTimeout("window.status=''",1000); <script language="LiveScript">

<!-- Hiding
  today = new Date()
  document.write("现 在 时 间 是: ",today.getHours(),":",today.getMinutes())
  document.write("<br>今 天 日 期 为: ", today.getMonth()+1,"/",today.getDate(),"/",today.getYear());
  document.write(document.lastModified)        //显示在页面上的时间(document.lastModified)
// end hiding contents -->
</script>

var MyArray= new initArray(17,18,19)。 //定义数组,下标从1开始
<INPUT TYPE="button" VALUE="Back" onClick="history.back()">   //后退
<INPUT TYPE="button" VALUE="JS- Home" onClick="location='script.html'"> //回主页
<INPUT TYPE="button" VALUE="Next" onCLick="history.forward()">  //前进
您 也 可 以 用 history.go(-1) 和 history.go(1) 代 替. 








javascript:window.location.reload(); 刷新页面
//只能输入数字(0-9)

onkeypress="if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false;"
//显示千位数(如:123456.123, 123,456.123
function commafy(num)
  {
   num = num+"";
   var re=/(-?\d+)(\d{3})/
   while(re.test(num))
   {
    num=num.replace(re,"$1,$2")
   }
   return num;
  }
toFixed(2)方法要求ie5.5以上版本   
  修改一下,判断是否number支持toFixed(),不支持就自己加上:  
  <script>  
  if(!Number.prototype.toFixed!)  
      {Number.prototype.toFixed=   function(num)  
          {with(Math)return   round(this.valueOf()*pow(10,num))/pow(10,num);  
          }  
      }  
  alert(3.1245.toFixed(2))  
  </script>
//只能输入数字
onkeypress="if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false;"