87,992
社区成员
发帖
与我相关
我的任务
分享JQuery:obj.on('click',function(){...});Object.prototype.on=function(eventName,fn){
document.all?this.attachEvent('on'+eventName,fn):this.addEventListener(eventName,fn,false);
};
var $=function(){return document.getElementById(arguments[0]);};
$('btn').on('click',function(){
alert('打印不出来');
});
得不到自己想要的结果,各位大侠看到的请各显神通,写出你们自己的js代码

this.obj = document.getElementById(arguments[0])//不要 || null;
function $(){
return new $.prototype.init(arguments[0]);
};
$.prototype = {
init: function() {
this.obj = document.getElementById(arguments[0]) || null;
},
on: function(eventName, fn) {
this.obj && (document.all? this.obj.attachEvent('on'+ eventName, fn) : this.obj.addEventListener(eventName, fn, false));
}
};
$.prototype.init.prototype = $.prototype;
$('btn').on('click', function(){
alert('打印不出来');
});