我在这里帮助学生,但是我需要一些建议:
它们具有包含带有一些锚标记的文章的模板。这些锚标记表示“向上移动,向下移动和删除”。
这些文章将动态更改位置。
我正在寻找的是:
在页面上的第一篇文章时,应删除“上移”锚点。如果物品位于底部/最后一个位置,则应卸下“向下移动”锚点。
如果物品处于中间位置,则所有锚点都必须可用。
我知道我可以将类应用于页面上的第一篇和最后一篇文章...但是我如何才能专门针对这些文章而又不在列表中。任何帮助,将不胜感激!
<script type="text/template" id="message-edit-item-template">
$(“。actions”)。first()。children()。remove(“。move-up”)
$(“。actions”)。last()。children()。remove(“。move-down”);
^这只是我的尝试。我在下面的锚点中添加了上移和下移类,但是如果不需要可以将其删除
<article class="well" data-message-id="<%= data.id %>">
<div class="message">
<div class="highlight clearfix">
<div class="actions">
<a href="#" data-remove="true" class="pull-right" title="Remove"><i class="fa fa-close"></i> Remove</a>
<a href="#" data-move-up="true" class="pull-right move-up" title="Move Up"><i class="fa fa-arrow-up"></i> Move Up</a>
<a href="#" data-move-down="true" class="pull-right move-down" title="Move Down"><i class="fa fa-arrow-down"></i> Move Down</a>
</div>
</div>
<div class="form-group">
<label>Title</label>
<input type="text" name="title" value="<%= data.title %>" class="form-control"/>
</div>
<div class="form-group">
<label>Message</label>
<textarea name="message" class="form-control"><%= data.message %></textarea>
</div>
</div>
</article>
最佳答案
您应该为此使用CSS。
.actions:first-child .move-up, .actions:last-child .move-down {
display: none;
}
当您添加或添加新元素时,浏览器将根据与CSS选择器匹配的元素自动显示/隐藏元素。
参见:
:first-child
:last-child