What does [object Object] mean?

后端 未结 10 2017
醉酒成梦
醉酒成梦 2020-11-22 03:22

I am trying to alert a returned value from a function and I get this in the alert:

[object Object]  

Here is the JavaScript code:



        
10条回答
  •  孤独总比滥情好
    2020-11-22 04:02

    [object Object] is the default toString representation of an object in javascript.

    If you want to know the properties of your object, just foreach over it like this:

    for(var property in obj) {
        alert(property + "=" + obj[property]);
    }
    

    In your particular case, you are getting a jQuery object. Try doing this instead:

    $('#senddvd').click(function ()
    {
       alert('hello');
       var a=whichIsVisible();
       alert(whichIsVisible().attr("id"));
    });
    

    This should alert the id of the visible element.

提交回复
热议问题