我對jQuery幾行代碼來操作HTML在頁面上應用更改。 jQuery的
$('#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>
#Remarks是一個元素ID,對頁面必須是唯一的;所以每個人只操作一個元素;你是否在使用類.Remarks?你能提供一個jsfiddle的例子嗎? –
請給我們您的HTML代碼 – mishik