首先。脚本在这里:
$(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());
});
});
和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对象来自ajax。我想将cntInfo的一部分复制到num2中!不动!但结果是[object Object]和GhostItem.prototype.setOwner函数不起作用。追加($(&#34;#cntInfo_owner&#34; + id))并不好。对象消失了。
我该如何解决?