window.onload 添加多个函数绑定
2024-09-04 13:10:40
window.onload = function(){alert(2)} function addEvent (fun) {
var old = window.onload; if(typeof old != "function"){
window.onload = fun;
}else{
window.onload = function(){
old();
fun();
}
}
} function delegationforli(){
var oul = document.getElementsByTagName('ul')[0];
console.log(oul)
oul.addEventListener('click',function(e){
console.log(e.target);
if(e.target && e.target.nodeName.toLowerCase() == 'li'){
alert(e.target.innerHTML);
}
})
}
addEvent(delegationforli);
用这种window.onload =function() { t(); b(); }方法函数的时候会看着很不爽,可以用上面的方法,更易读。
最新文章
- intellij idea使用
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
- POJ 3259 Wormholes (判负环)
- phaser
- [转]开源中国的 IT 公司开源软件整理计划介绍
- 识货的拿走:Android游戏框架解读之总体结构
- ios UICollectionView滑动时操作
- python auto send email
- GA遗传算法解析
- 【解决】Maven myeclipse出现Could not find the main class
- STL-空间配置器(allocator)
- CII-原子
- Apache Curator入门实战
- mysql安装和配置(windowns||centos)
- 自动生成 java 测试 mock 对象框架 DataFactory-01-入门使用教程
- How to change system keyboard keymap layout on CentOS 7 Linux
- postman笔记1--postman的安装教程
- Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=val错误
- Spring Data Redis 详解及实战一文搞定
- git命令详解( 二 )