`
mtnt2008
  • 浏览: 362905 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Jquery事件执行顺序

阅读更多

 

1.js中如何判断null

 

var exp = null;
if (!exp)
{
    alert("is null");
}

如果 exp 为 undefined 或者数字零,也会得到与 null 相同的结果,虽然 null 和二者不一样。注意:要同时判断 null、undefined 和数字零时可使用本法。

 

2.js时间处理函数

Syntax:

iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])

Parameters

vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer that specifies the number of milliseconds.
sLanguage Optional. String that specifies one of the following values:
JScript Language is JScript.
VBScript Language is VBScript.
JavaScript Language is JavaScript.

Return Value

Integer. Returns an identifier that cancels the evaluation with the clearTimeout method.

 

相似函数:

clearTimeout( iTimerID );

setInterval();

clearInterval();

 

3.事件执行顺序

 

举个例子:<input>的click事件弹出一个<div>,<div>中有一个链接<a>有个click事件,当你点击<a>时,要触发2个事件:<a>的click事件和<input>的blur事件

 

在firefox中事件的执行顺序:blur,click

 

现在,你想要事件的执行顺序:click,blur,那怎么实现呢?

 

这里使用时间延迟和达到效果,原理:

1.js单线程本质

2.延迟执行,模拟事件的执行顺序

 

setTimeout增加了Javascript函数调用的灵活性,为函数执行顺序的调度提供极大便利。

 

作者John的一篇文章:How JavaScript Timers Work ,你会对JavaScript单线程本质和 setTimeout以及setInterval有更加深刻的理解。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics