我有这些 Jquery 代码行来操作 HTML
$('#Remarks li:gt(1)').wrapAll('<ul class="btmRow" />');
$("#btRowMargin").appendTo("#Remarks");
$('#Remarks ul:lt(2)').wrapAll('<li class="btmRow" />');
我希望上面的代码在存在#Remarks 的页面中生效。为此我写了
$.each($("#Remarks"), function() {
$('#Remarks li:gt(1)').wrapAll('<ul class="btmRow" />');
$("#btRowMargin").appendTo("#Remarks ");
$('#Remarks ul:lt(2)').wrapAll('<li class="btmRow" />');
});
但这似乎不起作用。
最初的 HTML 看起来像这样
<li>
<ul id="Remarks" class="Remarks">
<li class="Header soldBKG">Showing Information</li>
<li><p><b>Remarks:</b></p></li>
<li><span>Occupant Name</span><span class="data">Listing Office</span></li>
<li><span>Occupancy/Show</span><span class="data">Listing Agent</span></li>
<li><span>Occupant Type</span><span class="data">N/A</span></li>
<li><span>Occupant Phone</span><span class="data">N/A</span></li>
<li><span>Other Phone Number</span><span class="data">N/A</span></li>
</ul>
<ul class="btmRow MarginFix" id="btmRowMarginFix">
<li></li>
<li><span>Phone To Show</span><span class="data">N/A</span></li>
<li><span>LockBox Location</span><span class="data">N/A</span></li>
<li><span>LockBox Type</span><span class="data">N/A</span></li>
<li><span>Showing Access</span><span class="data">N/A</span></li>
</ul>
</li>
应用 jquery 后,HTML 如下所示:
<li>
<ul id="Remarks" class="Remarks">
<li class="Header soldBKG">Showing Information</li>
<li><p><b>Remarks:</b></p></li>
<li class="btmRow">
<ul class="btmRow">
<li><span>Occupant Name</span><span class="data">Listing Office</span></li>
<li><span>Occupancy/Show</span><span class="data">Listing Agent</span></li>
<li><span>Occupant Type</span><span class="data">N/A</span></li>
<li><span>Occupant Phone</span><span class="data">N/A</span></li>
<li><span>Other Phone Number</span><span class="data">N/A</span></li>
</ul>
</li>
</ul>
<ul class="btmRow MarginFix" id="btmRowMarginFix">
<li></li>
<li><span>Phone To Show</span><span class="data">N/A</span></li>
<li><span>LockBox Location</span><span class="data">N/A</span></li>
<li><span>LockBox Type</span><span class="data">N/A</span></li>
<li><span>Showing Access</span><span class="data">N/A</span></li>
</ul>
</li>
但我想要这样:
<li>
<ul id="Remarks" class="Remarks">
<li class="Header soldBKG">Showing Information</li>
<li><p><b>Remarks:</b></p></li>
<li class="btmRow">
<ul class="btmRow">
<li><span>Occupant Name</span><span class="data">Listing Office</span></li>
<li><span>Occupancy/Show</span><span class="data">Listing Agent</span></li>
<li><span>Occupant Type</span><span class="data">N/A</span></li>
<li><span>Occupant Phone</span><span class="data">N/A</span></li>
<li><span>Other Phone Number</span><span class="data">N/A</span></li>
</ul>
<ul class="btmRow MarginFix" id="btmRowMarginFix">
<li></li>
<li><span>Phone To Show</span><span class="data">N/A</span></li>
<li><span>LockBox Location</span><span class="data">N/A</span></li>
<li><span>LockBox Type</span><span class="data">N/A</span></li>
<li><span>Showing Access</span><span class="data">N/A</span></li>
</ul>
</li>
</ul>
</li>