JQUERY 解决 addEventListener AND attachEvent

 

var Ka=navigator.userAgent.toLowerCase();
var rt=Ka.indexOf("opera")!=-1;
var r=Ka.indexOf("msie")!=-1&&(document.all&&!rt);
function Zl(a,b,c){if(r){a.attachEvent("on"+b,c)}else{a.addEventListener(b,c,false)}}

 

用JQUERY Bind 代替。

-
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
 <title>jQuery Events Example</title>
 <script type="text/javascript" src="../scripts/jquery-1.2.1.js">
 </script>
 <script type="text/javascript">
 $(function(){
 $('#vstar')
 .bind('click',function(event) {
 say('Whee once!');
 })
 .bind('click',function(event) {
 say('Whee twice!');
 })
 .bind('click',function(event) {
 say('Whee three times!');
 });
 });

 function say(text) {
 $('#console').append('<div>'+text+'</div>');
 }
 </script>
 </head>

 <body>
 <img id="vstar" src="vstar.jpg"/>
 <div id="console"></div>
 </body>
</html>
</html>
			
插入代码块
Source Code
两个插件怎么老用不好啊?哎
原文地址:https://www.cnblogs.com/xyicheng/p/1670689.html