javascript 跨浏览器的事件系统4
上次说到我们在无菌环境中设计了一个事件代理函数,但性能是个问题,解决它我们需要缓存节点集合,发现节点集合不足以应对新情况时,再替换这个节点集合,重新开始匹配。下面是新的方案:
var delegate = function(selector,type,callback){
var els = $(selector);
addEvent(document,type,function(e){
var flag = true;
var node = e.srcElement || e.target;
for(var i=0,el;el = els[i++];){
if(node === el){
flag = false;
return callback.call(node,e);
}
}
if(flag){
els = $(selector);
for(var i=0,el;el = els[i++];){
if(node === el){
return callback.call(node,e);
}
}
}
},true);
}
<!doctype html>
<html lang="zh-ch" id="html">
<head>
<meta charset="utf-8" />
<meta content="IE=8" http-equiv="X-UA-Compatible"/>
<title>事件代理 by 司徒正美</title>
<script type="text/javascript">
window.onload = function(){
var addEvent = function(el,type,callback,data){
if ( el.addEventListener ) {//如自定义对象就绑定回调函数了
el.addEventListener( type, callback, !!data );
} else if ( el.attachEvent ) {
el.attachEvent( "on" + type, function(){
return callback.call(el,window.event)
});
}
}
var delegate = function(selector,type,callback){
var els = $(selector);
addEvent(document,type,function(e){
var flag = true;
var node = e.srcElement || e.target;
for(var i=0,el;el = els[i++];){
if(node === el){
flag = false;
return callback.call(node,e);
}
}
if(flag){
els = $(select
相关文档:
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 对象 ......
$(document).ready(function() {
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
&nbs ......
父窗口中有三种方式打开子窗口:
1:
window.open(URL,windowName,parameters);
2:
alert(""); //弹出信息提示对话框
confirm(""); //弹出信息确认对话框
prompt(""); //具有交互性质的对话框
3:
//创建模态你对话框
window.showModalDialog(sURL,vArguments,sFeatures)
//创建非模态对话框
window.showM ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......