function Player()
{
this.width = 0;
this.height = 0;
};Player.prototype.show = function(w,h)
{
this.width = w;
this.height = h;
alert("width="+ this.width +";height="+ this.height);
};Player.prototype.check = function()
{
$("img").click(function(){
this.show(this.width,this.height);
//在这里要如何调用 show 这个方法,用以上方法总是出错
});
};var player = new Player();
player.check();

解决方案 »

  1.   


    this.show(this.width,this.height);
    用$(this).show($(this).width,$(this).height);试试看
      

  2.   

    Player.prototype.check = function()
    {
    var me = this;
    $("img").click(function(){
    me.show(me.width,me.height);
    });
    };
    要注意this指向的对象
      

  3.   


    $(function(){
    function Player(){
    this.width = 0;
    this.height = 0;
    };
    var player = new Player();
    Player.prototype.show = function(w,h){
    alert("ssssss"+w)
    this.width = w;
    this.height = h;
    alert("width="+ this.width +";height="+ this.height);
    };Player.prototype.check = function(){
    // alert("ss")
    $("img").click(function(){
    //alert(this.width)
    player.show(this.width,this.height);
    //在这里只能用player调用 show 这个方法,用以上方法总是出错
    });
    };
    player.check();//这个调用了check()函数
    });
      

  4.   


    Player.prototype.check = function(){
    // alert("ss")
        var temp = this;
    $("img").click(function(){
    temp.show(this.width,this.height);
    //在这里要如何调用 show 这个方法,用以上方法总是出错
    });
    };这样也行
      

  5.   

    this.show(this.width,this.height);
    此句的 this 指$("img")  而不是Player对象