易截截图软件、单文件、免安装、纯绿色、仅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评估用户输入密码的强度

    密码已经是我们生活工作中必不可少的工具,但一个不安全的密码有又有可能会给我们造成不必要的损失。作为网站设计者,如果我们在网页中能对用户输入的密码进行安全评估,并显示出相应的提示信息,那么对用户设置一个安全的密码将有很大帮助。同时也使得网站更具人性化,更有吸引力.
什么是一个安全的密码呢 ......

javascript: The Browser Object Model(BOM)

window
window对象是浏览器或者框架自身.top总是浏览器,parent是父框架,self表示自己.
window通常可以省略.
窗口操作: moveBy(dx, dy), moveTo(x, y),
resizeBy(dw, dh), resizeTo(w, h).
导航: window.open(url, frame
name, attribute). attribute可以是left, top, height, width, resizable,
scrollable, too ......

JavaScript日期转换为东八区的日期


                    var sDate = new Date(Date.UTC(arys[0], arys[1] - 1, arys[2]));
                    var eDate = new Date(Date.UTC(arys1[0], arys1[1] - 1, arys1[2]));
......

放一个javascript右键菜单的代码

注册很长时间号了,刚开通博客,拿出一个自己写的javascript右键菜单,兼容IE,firefox浏览器
这是css代码
 body{
font-size:12px;
}
.contextMenu{
filter:alpha(opacity=80);
opacity:0.8;
border:1px #0033FF solid;
background-color:#0099CC;
cursor:pointer;
width:120px;
position:absolute;
top: ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号