为IE的javascript提速
我们知道,javascript在执行期时是由内到外执行脚本的,那么离我们的脚本最远的全局对象,很可能要跨越几层作用域对能访问到它。不过在IE中,从最内层到最外层要花的时间比其他多出很多。加之,javascript是一种胶水语言,它必须要调用DOM对能完成我们大多数选择。最著名的就是选择元素(document.getElementById,document.getElementsByTagName,docuemnt.evaluate,document.querySelector),创建元素(document.createElement),此外还有document.body,document.defaultView.getComputedStyle等等,频繁地调用document对象,但是document是位于window对象下,因此这路程就更远了。就了提速,我们必须把它们保存在一个本地变量,那么每次就省得它长途跋涉了。这种技术的运用明显体现在jQuery的源码中:
(function( window, undefined ) {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
//====================省=================
}
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
})(window);
把window传进闭包内,就省得它每次都往外找window了。
再看其他类库
//Raphael
window.Raphael = (function () {
var separator = /[, ]+/,
elements = /^(circle|rect|path|ellipse|text|image)$/,
doc = document,
win = window,
//************略**************
//dojo
d.global = this;
//Ext
DOC = document,
//YUI
//************略************
} else if (i == 'win') {
c[i] = o[i].contentWindow || o[i];
c.doc = c[i].document;
//************略************
Y.config = {
win: window || {},
doc: document,
但是如果你没有引入类库,
相关文档:
描述
event代表事件的状态,例如触发event对象的元素、鼠标的位置及状态、按下的键等等。
event对象只在事件发生的过程中才有效。
event的某些属性只对特定的事件有意义。比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout 事件有意义。
例子
下面的例子检查鼠标是否在链接上单击,并且,如果shif ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript真正的鼠标放上动画加载大图的代码</title>
<style>
*{ padding:0; margin ......
今天在开发过程中遇到要用Js代码获取GridView中某个触发事件控件的ID,本人过去没有这样做过,这个问题在那时把我给难住了。
在网上找了好半天,终于是功夫不负有心人,答案还是让我给找到了!这也要感谢那个回帖的好心人。
解决方法就是:window.event.srcElement.id ,它可以当前获得触发事件控件的ID,控件知道了 ......
一、正则表达式通过RegExp类实现,RegExp对象的构造函数可以带一个或两个参数。第一个参数(或只有一个参数)是描述需要进行匹配的模式字符串,如果还有第二个参数,这个参数则指定了额外的处理指令。
定义正则表达式:
1、只匹配字符串中出现的第一个单词"cat";区分大小写
var reCat = new RegExp("cat&q ......
昨天去老家的书店买了本《JavaScript征途》,这本书。。。娘娘,。。这书还真他妈的贵。。原价。。89.00,打完折还有80.00我操。。
看来计算机类的图书还不是一般的价类。。。
想想。。。自己还有好多的技术没有学完的类。。。XHTML,CSS,JavaScript,C#2.0,c#3.0.。asp.net2.0,asp.net3.5
现在c#又要出4.0了。。。我 ......