惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
S
Secure Thoughts
P
Palo Alto Networks Blog
Google DeepMind News
Google DeepMind News
AI
AI
H
Hacker News: Front Page
Schneier on Security
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
T
Tor Project blog
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
S
Security @ Cisco Blogs
S
Security Affairs
P
Privacy International News Feed
I
Intezer
S
SegmentFault 最新的问题
F
Full Disclosure
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Securelist
V
Vulnerabilities – Threatpost
C
CERT Recently Published Vulnerability Notes
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA
Attack and Defense Labs
Attack and Defense Labs
Forbes - Security
Forbes - Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
WordPress大学
WordPress大学
Vercel News
Vercel News
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
美团技术团队
IT之家
IT之家
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
D
Docker
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hugging Face - Blog
Hugging Face - Blog

博客园 - nect

【转】ie9 rc版软件兼容问题 [z]前端设计IE6/IE7/IE8/IE9/FF问题汇总:IE和FirFox兼容问题 - nect - 博客园 [z]ie和FF 在insertRow和insertCell的区别 WinForm使用webclient通过http的POST方式上传文件 转:另类解决:“ScriptManager”不是已知元素。原因可能是网站中存在编译错误。 - nect - 博客园 转:css妙用1-用图片替换文字 .net中的正则表达式(一)——转义字符 使用Cascadingdropdown控件遇到的一个问题 IP地址匹配算法 服务器控件的客户端验证脚本 从一个字符串中Remove另一个字符串 gridview 中模板列无法响应row_command事件 - nect - 博客园 在asp.net Atlas中调用 Web Service时无法找到自定义的Web Service对象的可能原因 【转】Prototype.js开发笔记//mark一下 在GridView中使用邮件链接 【转】ASP.net2。0中解决无法获取 GridView 隐藏列值问题 GridView 中格式化整理 [转]操纵自如--页面内的配合与通信 [导入]Java调用.net的WebService
[z]JS在IE和FF下attachEvent,addEventListener学习笔记 - nect - 博客园
nect · 2010-10-15 · via 博客园 - nect

今天小弄了一下JS事件,主要说一下FF和IE兼容的问题

对象名.addEventListener("事件名(不带ON)",函数名,true/false);(FF下)
对象名.attachEvent("事件名",函数名);(IE下)

说明:
  事件名称,要注意的是"onclick"要改为"click","onblur"要改为"blur",也就是说事件名不要带"on"。
函数名,记住不要跟括号最后一个参数是个布尔值,表示该事件的响应顺序,下面重点介绍一下addEventListener的第3个参数(useCapture)。 userCapture若为true,则浏览器采用Capture,若为false则采用bubbing方式。建议用false,看个例子吧。
html代码
<div id="div_test"> <input type="button" id="btn_test" value="se4.cn技术基地" /> </div>
js代码

代码

window.onload=function(){ document.getElementById("div_test").addEventListener("click",test1,false); document.getElementById("btn_test").addEventListener("click",test2,false); } function test1(){ alert("外层div触发") } function test2(){ alert("内层input触发") } 

自己体验一下,如果userCapture是true则test1先触发,如果userCapture是false则test2先触发。

下面来说一下,attachEvent
这个没啥好说的,相信大家也都用的挺熟的,主要是传参那块,等我用到 再说吧,哈哈哈

示例:
创建绑定方法:

if (typeof document.addEventListener != "undefined") { 
document.addEventListener(
"mousedown",_lhlclick,true); 
else { 
document.attachEvent(
"onmousedown",_lhlclick); 

删除事件:

if (typeof document.addEventListener != "undefined") { 
document.removeEventListener(
"mousedown",_lhlclick,true); 
else { 
document.detachEvent(
"onmousedown",_lhlclick);