this.div=$j("<div class='test' id='test"+this._x+"'>"+this.getHtml(inner)+"<a id='testa"+this._x+"''>Close</a></div>");
this.div.hide().appendTo($j("body")).fadeIn(100);
this.div.children("#testa"+this._x).bind('click', function(){
alert(this._x);
});
in constructor
开发者_如何学编程this._x = x;
x++;
when i click testa he gives me this._x last x number is there an override?
Yes, JS events are tied to the element itself. If you delete and recreate an element the handlers go with it. You can either re-connect them, or look into using jQuery's .live() functionality.
this._x in your event listener points to non existant property of (A._x).
this.div=$j("<div class='test' id='test"+this._x+"'>"+this.getHtml(inner)+"<a id='testa"+this._x+"''>Close</a></div>");
this.div.hide().appendTo($j("body")).fadeIn(100);
var newX = this._x;
this.div.children("#testa"+this._x).bind('click', function(){
alert(newX);
});
精彩评论