<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="原生js事件绑定和事件移除" id="card1">
<p> 游客</p><p>
标题:原生js事件绑定和事件移除<br/>
正文:<br/>
用惯了框架，什么jQuery/Ext/zepto/underscore/backbone 绑定事件on,bind,addListener，如果没有这些框架，原生的js怎么写？你能立刻写出来吗？ 绑定事件的好处：    一个对象可以绑定多个不同事件    一个对象可以绑定多个相同事件（按照绑定的顺序执行。注意IE下顺序相反）测试地址js代码如下：/** * @description 事件绑定，兼容各浏览器 * @param target 事件触发对象  * @param type   事件 * @param func   事件处理函数 */function addEvents(target, type, func) {    if (target.addEventListener)    //非ie 和ie9        target.addEventListener(type, func, false);    else if (target.attachEvent)   //ie6到ie8        target.attachEvent(&amp;quot;on&amp;quot; + type, func);    else target[&amp;quot;on&amp;quot; + type] = func;   //ie5};/** * @description 事件移除，兼容各浏览器 * @param target 事件触发对象 * @param type   事件 * @param func   事件处理函数 */function removeEvents(target, type, func){    if (target.removeEventListener)        target.removeEventListener(type, func, false);  &amp;nbs<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=674&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=674&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=674&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=674&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=674">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=674">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>