日期:2014-05-16 浏览次数:20403 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
</head>
<body>
<div id='divId'>按钮</div>
<script type='text/javascript'>
var Class = function(parent){
var klass = function(){
this.init.apply(this, arguments);
};
klass.prototype.init = function(){};
klass.fn = klass.prototype;
klass.extend = function (obj) {
var extended = obj.extended;
for (var i in obj) {
klass[i] = obj[i];
}
if (extended) extended(klass)
};
klass.include = function (obj) {
var included = obj.included;
for (var i in obj) {
klass.fn[i] = obj[i];
}
if (included) included(klass)
};
klass.proxy = function(func){
var self = this;
return(function(){
//return func.apply(self, arguments);
func.apply(self, arguments);
});
}
klass.fn.proxy = klass.proxy;
return klass;
};
var Button = new Class;
Button.include({
/*init: function(element){
this.element = jQuery(element);
this.element.click(this.proxy(this.click));
//$(document.getElementById('#divId')).click(this.proxy(this.click));
},
click: function(){ alert('btn'); }*/
init: function(element){
this.element = jQuery(element);
this.element.click(this.proxy(this.click));
//this.element.click(this.click);
//$(document.getElementById('#divId')).click(this.proxy(this.click));
},
click: function(){ alert(this.element); }
});
var divs = document.getElementById("divId");
var buttons = new Button(divs);
</script>
</body>
</html>