2012-10-08 36 views
-2

试图在点击事件中获取对象。我在这里做错了什么? 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?

+0

对不起,我该怎么办呢? – user1158040

+0

好吧修好了。希望可以有人帮帮我! – user1158040

回答

0

试图

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

$(<selector>).parent() 

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

+0

嗯,我不想获取父元素,但在代码中的持有按钮的对象。所以我可以引用在按下按钮后触发的函数中的每个对象。 – user1158040

+0

我需要一些更好的描述来描述你正试图实现的目标? 你可以 'click',function(event){event.preventDefault(); }); – P6345uk

+0

好的,谢谢,再次看看,我编辑了我的问题。 – user1158040

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);    

     } 
    }​