var append = $('<li class="ui-widget-content" id="list-'+num+'">'+content+'</li>');
console.log( append ); // LOG: [object Object]
console.log( append.html() ); // LOG: null
IE 8创建var append
作为对象,但其html内容为null
。在其他浏览器中正常工作。我无法弄清楚这里有什么问题。有什么想法吗?
// //编辑
var content
是一个ajax响应html字符串,就像这样
<div class="item status-0 filiale-2" id="item-18">
<div class="ui-corner-all date ui-state-active">
<div class="filiale">Düren</div>
<div class="left date-add">22.06.2011 15:02:24 Uhr</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div>
<form id="form-order-18" action=""">
<input type="hidden" id="list-id" name="id" value="18" >
<div class="relative left artikel"><input type="text" class="text ui-corner-all ui-widget-content autocomplete" id="list-artikel-18" name="artikel" value="79949 | ASUS Eee PC 1001PXD-BLK028S 25.65cm/N455/1" /></div>
<div class="relative left qty"> <input type="text" class="text ui-corner-all ui-widget-content" id="list-qty-18" name="qty" value="1" /></div>
<div class="relative left comment"><input type="text" class="text ui-corner-all ui-widget-content" id="list-comment-18" name="comment" value="kunde wünscht ungeöffnetes" /></div>
<div class="relative left">
<button type="button" class="item-edit" opt:icon="ui-icon-disk" opt:text="false">Änderungen speichern</button>
<button type="button" class="item-del" item:id="18" opt:icon="ui-icon-trash" opt:text="false">Bestellung Löschen</button>
</div>
</form>
</div>
<div>
<form id="form-sendorder-18">
<input type="hidden" name="action" value="sendorder" />
<input type="hidden" id="order-id" name="id" value="18" >
<div class="relative left salesman">
<label for="order-artikel-18" class="ui-state-disabled text">Händler</label>
<input type="text" class="text ui-corner-all ui-widget-content acsalesman inlinefield" id="order-artikel-18" name="salesman" value="" />
</div>
<div class="relative left dateexpected">
<label for="order-list-date-expected-18" class="ui-state-disabled text">erwartet am</label>
<input type="text" class="text ui-corner-all ui-widget-content inlinefield datepicker" id="order-list-date-expected-18" name="date_expected" value="" />
</div>
<div class="relative left comment">
<label for="order-comment-18" class="ui-state-disabled text">Kommentar für Filiale</label>
<input type="text" class="text ui-corner-all ui-widget-content inlinefield" id="order-comment-18" name="comment_o" value="" /></div>
<div class="relative left">
<button type="button" class="item-order" opt:icon="ui-icon-cart" opt:text="false" item:id="18">Ware Bestellt</button>
</div>
</form>
</div>
<div class="clear"></div>
此字符串是问题所在。如果我设置没有这个字符串的html,它就可以工作。
var append = $('<li class="ui-widget-content" id="list-'+num+'">foobar</li>');
console.log( append ); // LOG: [object Object]
console.log( append.html() ); // LOG: foobar
谢谢&amp;的问候,
亚历
答案 0 :(得分:0)
.html()相当于innerHTML(),这意味着在普通浏览器(例如FF,Chrome)中它应该正确,而在IE中你必须使用outerHTML属性。
我尝试使用outerHTML jQuery插件来完全获取元素:http://yelotofu.com/2008/08/jquery-outerhtml/
希望有所帮助:)