这应该很简单,但由于我无法理解,它不起作用,更重要的是,我找不到要求Google提供的正确问题!JS类和重写JQuery事件处理程序
我想要做的就是按照下面的原则为JS类创建一个事件绑定器,除非我直接在盒子对象上调用.bind(),否则实际发生的事情并不算什么。
function Box()
{
this.Width = 200;
this.Height = 200;
this.WrapperClass = "boxWrapper";
this.TitleClass = "boxTitle";
this.ContentClass = "boxContents";
this.Title = "This is a box";
this.Content = "This is some box contents";
}
Box.prototype.Html = function()
{
var box = $('<div></div>').addClass(this.WrapperClass);
box.append($("<div></div>").addClass(this.TitleClass).append(this.Title));
box.append($("<div></div>").addClass(this.ContentClass).append(this.Content));
box.width(this.Width);
box.height(this.Height);
return box.outerHTML();
}
Box.prototype.Bind = function(event, eventDelegate)
{
this.bind(event, eventDelegate);
}
function clickDelegate(message)
{
alert(message);
}
$(document.ready(function() {
var box = $(new Box().Html());
box.Bind('click', clickDelegate('text'));
$('body').append(box);
}
'box'是一个jQuery对象,它没有大写字母的'.Bind'。 – pimvdb