点击按钮访问父对象?

时间:2012-10-08 12:46:39

标签: jquery

尝试在click事件中获取对象。我在这做错了什么? this.section是每个按钮的索引。

  this.ebutton        = jQuery('.episode_button');
  this.button         = this.ebutton.eq(this.section);
  this.listtext       = 'testbutton';

  this.button.parobj  = this;
  this.button.bind('click', function() {

    alert(this.parobj.listtext());

   });

如何在按钮事件中获取属性listtext?

2 个答案:

答案 0 :(得分:0)

尝试了

$("#"+this.id).parent()

$(<selector>).parent()

http://api.jquery.com/parent/

答案 1 :(得分:0)

     var epi = {};

     /*Startpage*/
     epi.start = {
         epilist:            [],

         init: function () {
             this.ebutton                = jQuery('.episode_button');
             this.episodelist.prototype  = this;

             this.epilist.push(new this.episodelist(0));
         },


         episodelist: function (index) {
             this.name           = 'test'
             this.button         = this.ebutton.eq(index);
             this.button.parobj  = this;
             this.button.bind('click', function() {this.parobj.episodelistshow();});
         },

         episodelistshow: function () {

             // This will not alert correctly!
             // Should alert test
              alert(this.name);            

         }
     }​