易截截图软件、单文件、免安装、纯绿色、仅160KB

Javascript简易计时器(用来记算代码的执行时间)

自己写的一个简易计时器,能记算代码的执行时间,还可以拿来测试代码的执行效率。
function Counter(){
this.start();
}
Counter.prototype.getTime = function(){
var time = new Date();
return time.getSeconds()*1000+time.getMilliseconds();
}
Counter.prototype.start = function(){
this.counting = true;
this.startTime = this.getTime();
}
Counter.prototype.stop = function(){
if(this.counting == true){
this.counting = false;
this.stopTime = this.getTime();
}
}
Counter.prototype.show = function(){
this.counting==true && this.stop();
this.time = this.stopTime-this.startTime;
document.write('执行代码花费了 '+this.time+' 毫秒<br>');
this.start();
}
使用示例如下:
var myCounter = new Counter();
for(var i=0;i<500;i++){
document.write('|');
}
myCounter.show();
var myCounter2 = new Counter();
document.write('<br>');
myCounter2.start(); //重新开始计时
for(var i=0;i<500;i++){
document.write('*');
}
myCounter2.stop(); //停止计时
for(var i=0;i<500;i++){
document.write(';');
}
myCounter2.show(); //这里显示的时间是执行第一次for循环所用的时间(就是输出一排*的那个)
在创建对象后会自动开始计时。
调用对象的start()方法将重新开始计时。
调用stop()方法会停止计时。
show()方法用来显示代码执行的时间(如果调用show()方法前没有调用过stop(),会自动调用一次)
多个计时对象之间互不影响。
因为我还是个菜鸟,希望大家对我的不足之处点评指正!


相关文档:

javascript 动态给IFRAME添加数据


<iframe width='100%' height='100%' name='boot' id='boot' src='' frameborder='0' scrolling='no'></iframe>
<SCRIPT   LANGUAGE="JavaScript">  
<!--  
var iframe = window.frames['boot'];
iframe.document.open();
iframe.document.write('<!DOCTY ......

Javascript 类和命名空间的定义

//1.类
function Test(id)
{
     this.id=id;
     this.method=function()
         {
            //代码
         };
}
......

JavaScript 判断浏览器类型及版本

$(document).ready(function() {
        var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        if (window.ActiveXObject)
        &nbs ......

介绍怎样解决JavaScript页面刷新与弹出窗口的问题。

 介绍怎样解决JavaScript页面刷新与弹出窗口的问题。
  1.无提示刷新网页
  大家有没有发现,有些网页,刷新的时候,会弹出一个提示窗口,点“确定”才会刷新。
  而有的页面不会提示,不弹出提示窗口,直接就刷新了.
  如果页面没有form,则不会弹出提示窗口。如果页面有form表单,
  a)< fo ......

[转]javascript判断浏览器类型与版本

要想写出跨浏览器的javascript,就必须懂得嗅探技术。这是浏览器大战遗留下的大地雷,事已如此,只好认命,乖乖写分支结构吧,函数就是这样不知不觉中变长的。
先看单一浏览器的判断,我们没有必须去找navigator.userAgent的麻烦,我在国外的博客网站收集了如下hack,短小精悍:
 
ie = !+"\v1" ;
ie ='\v'=='v' ; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号