这是我想要操作的html片段:
<ul>
<li data-action="CRMEVENTSTREAM" data-parameters="" data-id="3084314321" class="action"><span data-i18n="ui.EVENT_STREAM">Event Stream</span></li>
<li data-action="APPCALENDARVIEW" data-parameters="" data-id="3084314323" class="action"><span data-i18n="ui.CALENDAR">Calendar</span></li>
<li data-action="CRMCUSTOMERSVIEW" data-parameters="" data-id="3084314324" class="action"><span data-i18n="ui.CUSTOMERS">Customers</span></li>
<li data-action="PROFILEEDITDLG" data-parameters="DM_CC" data-id="3084314325" class="action"><span data-i18n="ui.PROFILE_EDITOR">Profile Editor</span></li>
<li class="k-separator"></li>
<li data-action="VIEWCASHMOVEMENT" data-parameters="" data-id="3084314327" class="action"><span data-i18n="ui.CASH_MOVEMENT">Cash Movement</span></li>
<li data-action="CRMAPPLICATIONLIST" data-parameters="" data-id="3084314328" class="action"><span data-i18n="ui.APPLICATION_LIST">Application List</span></li>
<li class="k-separator"></li>
<li data-action="CRMRELATIONEDITOR" data-parameters="" data-id="2998116122" class="action"><span data-i18n="ui.CUSTOMER_RELATION_EDITOR">Customer Relation Editor</span></li>
<li data-action="CRMMULTIRELEDITOR" data-parameters="" data-id="2998116123" class="action"><span data-i18n="ui.MULTIPLE_RELATION_EDITOR">Multiple Relation Editor</span></li>
<li data-action="CRMMASSRELEDITOR" data-parameters="" data-id="2998116124" class="action"><span data-i18n="ui.MASS_RELATION_EDITOR">Mass Relation Editor</span></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
<li data-action="CRMAPPLICATIONS" data-parameters="" data-id="2998116157" class="action"><span data-i18n="ui.CUSTOMER_APPLICATIONS">Customer Applications</span></li>
<li data-action="CRMCALLLOG" data-parameters="" data-id="2998116187" class="action"><span data-i18n="ui.PHONE_CALLS">Phone Calls</span></li>
<li data-action="CRMCRASEDITOR" data-parameters="" data-id="2998116189" class="action"><span data-i18n="ui.CR_STATUS_EDITOR">CR Status Editor</span></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
</ul>
这个html是由来自Web套接字的命令动态创建的。但是我不希望 li 标签具有 ul 标签的第一个或最后一个孩子 k-seperator 。而且我也不希望连续的 li 标签有 k-separator 。
我的目标是拥有以下html:
<ul>
<li data-action="CRMEVENTSTREAM" data-parameters="" data-id="3084314321" class="action"><span data-i18n="ui.EVENT_STREAM">Event Stream</span></li>
<li data-action="APPCALENDARVIEW" data-parameters="" data-id="3084314323" class="action"><span data-i18n="ui.CALENDAR">Calendar</span></li>
<li data-action="CRMCUSTOMERSVIEW" data-parameters="" data-id="3084314324" class="action"><span data-i18n="ui.CUSTOMERS">Customers</span></li>
<li data-action="PROFILEEDITDLG" data-parameters="DM_CC" data-id="3084314325" class="action"><span data-i18n="ui.PROFILE_EDITOR">Profile Editor</span></li>
<li class="k-separator"></li>
<li data-action="VIEWCASHMOVEMENT" data-parameters="" data-id="3084314327" class="action"><span data-i18n="ui.CASH_MOVEMENT">Cash Movement</span></li>
<li data-action="CRMAPPLICATIONLIST" data-parameters="" data-id="3084314328" class="action"><span data-i18n="ui.APPLICATION_LIST">Application List</span></li>
<li class="k-separator"></li>
<li data-action="CRMRELATIONEDITOR" data-parameters="" data-id="2998116122" class="action"><span data-i18n="ui.CUSTOMER_RELATION_EDITOR">Customer Relation Editor</span></li>
<li data-action="CRMMULTIRELEDITOR" data-parameters="" data-id="2998116123" class="action"><span data-i18n="ui.MULTIPLE_RELATION_EDITOR">Multiple Relation Editor</span></li>
<li data-action="CRMMASSRELEDITOR" data-parameters="" data-id="2998116124" class="action"><span data-i18n="ui.MASS_RELATION_EDITOR">Mass Relation Editor</span></li>
<li class="k-separator"></li>
<li data-action="CRMAPPLICATIONS" data-parameters="" data-id="2998116157" class="action"><span data-i18n="ui.CUSTOMER_APPLICATIONS">Customer Applications</span></li>
<li data-action="CRMCALLLOG" data-parameters="" data-id="2998116187" class="action"><span data-i18n="ui.PHONE_CALLS">Phone Calls</span></li>
<li data-action="CRMCRASEDITOR" data-parameters="" data-id="2998116189" class="action"><span data-i18n="ui.CR_STATUS_EDITOR">CR Status Editor</span></li>
</ul>
如何使用jquery操作dom?
谢谢,
答案 0 :(得分:6)
请注意,您要在取出第一个和最后一个之前删除相邻的兄弟姐妹。
$('li.k-separator + li.k-separator').remove();
$('li.k-separator:first-child, li.k-separator:last-child').remove();