javascript - 将 ul 中的第一项插入到最后

标签 javascript jquery html css

我研究了如何使用 $("#slideShow1 ul li:first").appendTo('#slideshow1 ul'); 将 ul 中的第一项附加到最后一项我想为幻灯片添加一些额外的效果,但我发现即使移动 li 元素也不起作用。

这是关于 http://jsfiddle.net/7L4b8cbd/4/ 的 html 和演示

<div id="slideShowContainer">
    <div id="slideShow">

        <ul>
            <li><img src="http://demo.tutorialzine.com/2010/11/rotating-slideshow-jquery-css3/img/photos/1.jpg" width="100%" alt="Fish" /></li>
            <li><img src="http://demo.tutorialzine.com/2010/11/rotating-slideshow-jquery-css3/img/photos/2.jpg" width="100%" alt="Ancient" /></li>
            <li><img src="http://demo.tutorialzine.com/2010/11/rotating-slideshow-jquery-css3/img/photos/3.jpg" width="100%" alt="Industry" /></li>
            <li><img src="http://demo.tutorialzine.com/2010/11/rotating-slideshow-jquery-css3/img/photos/4.jpg" width="100%" alt="Rain" /></li>
        </ul>

    </div>

    <a id="previousLink" href="#">&raquo;</a>
    <a id="nextLink" href="#">&laquo;</a>

</div>

jQuery

$("#slideShow ul li:first").appendTo('#slideshow ul');
$("#slideShow ul li:first").appendTo('#slideshow ul');
$("#slideShow ul li:first").appendTo('#slideshow ul');

编辑: 我现在引用的是正确的 ul,但它现在仍在工作。

最佳答案

我不知道你的三个 jQuery 语句是如何工作的,但下面的代码应该可以完成这项工作:

var x = $("#slideShow ul li:first");
$("#slideShow ul li:first").remove();
$('#slideShow ul').append(x);

这会将第一个元素移动到最后一个。根据需要重复多次。

结帐 - http://jsfiddle.net/7L4b8cbd/5/

关于javascript - 将 ul 中的第一项插入到最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32203067/

相关文章:

javascript - 是否可以在 CkEditor 或 TinyMce 中从编辑器中拆分工具栏或菜单栏?

javascript - 为什么在映射此数组时出现空错误?

c# - Css display none 不适用于 div 及其内容

javascript - jQuery - 锁定滚动条并防止页面跳转到顶部?

javascript - 通过 onsubmit 和 onclick 进行表单输入验证有什么区别?

javascript - 匹配文本中的多个关键字(Javascript)

javascript - 如何将一条消息中包含的 JSON 对象数组转换为多个 JSON 对象消息?

javascript - 即使从 DOM 中删除后,动态添加的功能仍在运行

javascript - 如何使旋转木马在滚动和悬停时不晃动

html - body 不会拉伸(stretch)以适应它的内容