获取拖放列表值的某种方法?

时间:2018-06-12 18:26:16

标签: javascript html css html5 font-awesome

我正在寻找一些拖放列表,我发现了这个:

https://codepen.io/Liskanth/pen/wqaReo

$(function() {
  $( "ul" ).sortable();
  $( "ul" ).disableSelection();
});

我有一个带有一些图片的旋转木马,我的目标是编辑这个图像顺序,就像列表中的示例一样,但我不知道如何通过jquery o某种方式获得这个有序列表的值。 / p>

修改

共享代码

<div class='csslider1 autoplay '>
    <input name="cs_anchor1" id='cs_slide1_0' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_slide1_1' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_slide1_2' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_slide1_3' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_slide1_4' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_slide1_5' type="radio" class='cs_anchor slide' >
    <input name="cs_anchor1" id='cs_play1' type="radio" class='cs_anchor' checked>
    <input name="cs_anchor1" id='cs_pause1_0' type="radio" class='cs_anchor pause'>
    <input name="cs_anchor1" id='cs_pause1_1' type="radio" class='cs_anchor pause'>
    <input name="cs_anchor1" id='cs_pause1_2' type="radio" class='cs_anchor pause'>
    <input name="cs_anchor1" id='cs_pause1_3' type="radio" class='cs_anchor pause'>
    <input name="cs_anchor1" id='cs_pause1_4' type="radio" class='cs_anchor pause'>
    <input name="cs_anchor1" id='cs_pause1_5' type="radio" class='cs_anchor pause'>
    <ul>
        <li class="cs_skeleton"><img src="cssslider_files/csss_images1/image1.jpg" style="width: 100%;"></li>
        <li class='num0 img slide'> <img src='cssslider_files/csss_images1/image1.jpg' alt='banner1' title='banner1' /></li>
        <li class='num1 img slide'> <img src='cssslider_files/csss_images1/image2.jpg' alt='banner2' title='banner2' /></li>
        <li class='num2 img slide'> <img src='cssslider_files/csss_images1/image3.jpg' alt='banner3' title='banner3' /></li>
        <li class='num3 img slide'> <img src='cssslider_files/csss_images1/image4.jpg' alt='banner4' title='banner4' /></li>
        <li class='num4 img slide'> <img src='cssslider_files/csss_images1/image5.jpg' alt='banner5' title='banner5' /></li>
        <li class='num5 img slide'> <img src='cssslider_files/csss_images1/image6.jpg' alt='banner6' title='banner6' /></li>
    </ul>


    <div class='cs_arrowprev'>
        <label class='num0' for='cs_slide1_0'><span><i></i><b></b></span></label>
        <label class='num1' for='cs_slide1_1'><span><i></i><b></b></span></label>
        <label class='num2' for='cs_slide1_2'><span><i></i><b></b></span></label>
        <label class='num3' for='cs_slide1_3'><span><i></i><b></b></span></label>
        <label class='num4' for='cs_slide1_4'><span><i></i><b></b></span></label>
        <label class='num5' for='cs_slide1_5'><span><i></i><b></b></span></label>
    </div>
    <div class='cs_arrownext'>
        <label class='num0' for='cs_slide1_0'><span><i></i><b></b></span></label>
        <label class='num1' for='cs_slide1_1'><span><i></i><b></b></span></label>
        <label class='num2' for='cs_slide1_2'><span><i></i><b></b></span></label>
        <label class='num3' for='cs_slide1_3'><span><i></i><b></b></span></label>
        <label class='num4' for='cs_slide1_4'><span><i></i><b></b></span></label>
        <label class='num5' for='cs_slide1_5'><span><i></i><b></b></span></label>
    </div>
    <div class='cs_bullets'>
        <label class='num0' for='cs_slide1_0'> <span class='cs_point'></span>
            </label>
        <label class='num1' for='cs_slide1_1'> <span class='cs_point'></span>
            </label>
        <label class='num2' for='cs_slide1_2'> <span class='cs_point'></span>
            </label>
        <label class='num3' for='cs_slide1_3'> <span class='cs_point'></span>
            </label>
        <label class='num4' for='cs_slide1_4'> <span class='cs_point'></span>
            </label>
        <label class='num5' for='cs_slide1_5'> <span class='cs_point'></span>
            </label>
    </div>
    </div>

1 个答案:

答案 0 :(得分:0)

首先,您需要挂钩.sortable()内部的事件,该事件将返回有关被拖动内容的信息(其文档在此处:http://api.jqueryui.com/sortable

然后你可以使用jQuery潜入列表。

这是我操纵的一个例子: https://codepen.io/anon/pen/MXmzvL

$(function() {
    $( "ul" ).sortable(
      {
  stop: function( event, ui ) {
    var idList = [];    
    $("ul").children("li").each(function(){
      idList.push($(this).attr('id')); 
    });

    console.log(idList);
  }
}
    );
    $( "ul" ).disableSelection();
  });

请注意,我在li元素中添加了id以帮助跟踪,但您可以使用内容来执行此操作。