简体   繁体   English

Jquery:对象返回值'[object Object]'

[英]Jquery: Object returns value '[object Object]'

irst at all.首先。 Script is here:脚本在这里:

$(function () {
    var type = 'REP';
    var id = '_r_2059281920';

    $(".math").click(function () {
        function GhostItem(type, owner, index, id, num) {
            this.gstType = type;
            this.gstThumb = "<div class='gst-label gst-pic-01'></div>";
            this.gstOwner = owner;
            this.gstIndex = index;
            this.gstId = id;
            this.gstNum = num;
        }

        GhostItem.prototype.toHTML = function () {
            var out = ""
            out = "<div class='item-mode' >" +
                "<div class='gst-fld gst-label " + this.gstType + "' ></div>" + this.gstThumb +
                "<div class='gst-label gst-owner'><h6>" + this.gstOwner + " </h6><h5>" + this.gstIndex + "</h5></div>" +
                "<div class='gst-label gst-cls '></div>" + this.gstNum + "</div>";
            return out;
        }

        var ghost_item = new GhostItem(type, $(type + id + " h4"), $(type + id + " h5"), '201034545323_a1243098382', '9934595023122');

        GhostItem.prototype.setOwner = function () {
            $(this.gstThumb).append($("#cntInfo_owner" + id));
        }

        ghost_item.setOwner();

        $(".num").append(ghost_item.gstOwner, ghost_item.gstIndex);
        $(".num2").append(ghost_item.toHTML());
    });
});

and html:和html:

<div class="cntInfo" id="cntInfo_r_2059281920">
    <div class="wrap">
        <div id="cntInfo_owner_r_2059281920" style="float: left; margin: 5px;">
            <img width="30" height="30" src="http://gyg.altuxa.com/files/2009/06/michael_jackson.jpg?file=2009/06/michael_jackson.jpg">
        </div>
        <div class="cntInfowide wrap lfloat" id="REP_r_2059281920">
            <div class="cntIB cntTitle rbor01 lfloat" id="REP_r_2059281920">
                <div class="cInfo_p_headline p_h_4_headline">
                    <h4>MichaelJacksonIsNotDead</h4>
                </div>
                <div class="cInfo_p_headline p_h_5_headline">
                    <h5>The New Yorkers</h5>
                </div>
            </div>
            <!-- others object -->
        </div>
    </div>
</div>
 <h2>Javascript Object 'this' Testing</h2>

<button class="math">Click here</button>
<div class="num">
    <p>num</p>
</div>
<div class="num2">
    <p>num 2</p>
</div>

cntInfo html object came from ajax. cntInfo html 对象来自 ajax。 I want to copy a part of cntInfo into num2!我想将cntInfo的一部分复制到num2中! Not move!不动! but result is [object Object] and GhostItem.prototype.setOwner function doesn't work.但结果是 [object Object] 并且 GhostItem.prototype.setOwner 函数不起作用。 append($("#cntInfo_owner" + id)) is no good. append($("#cntInfo_owner" + id)) 不好。 Object Gone away.对象消失了。

How can I solve it?我该如何解决?

I had called the constructor with 6 arguments, but it only has 5 parameter variables.我用 6 个参数调用了构造函数,但它只有 5 个参数变量。 Thanks Barmar谢谢巴尔玛

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM