Sortable不适用于模式,但可在启动模式的页面上使用

时间:2018-09-06 06:35:53

标签: javascript html5 jquery-ui-sortable

我目前正在尝试使用模态中的拖放操作来使列表可重新排序。我的模态在下面...

<div class="modal fade" id="settingsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg"> 
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">Settings</h4>
        </div>

        <div class="modal-body">

            <ul id="sortable">

                <li data-id="1" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 1</li>
                <li data-id="2" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 2</li>
                <li data-id="3" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 3</li>

            </ul>

        </div>

        <div class="modal-footer">

          <button id="save-reorder" type="button" class="btn btn-primary">Save</button>

        </div>

      </div>
    </div>
 </div>

JavaScript看起来像这样...

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

当我在启动模式的页面上使用此代码时,它工作正常。我不确定为什么这在模式中也不起作用。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

请尝试使用此代码。

<!DOCTYPE html>
<head>

  <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="bootstrap.min.css" >

    <script src="jquery-ui.min.js" type="text/javascript"></script>



</head>

    <div class="modal fade" id="settingsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> 
    <div class="modal-dialog modal-lg"> 
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">Settings</h4>
        </div>

        <div class="modal-body">

            <ul id="sortable">

                <li data-id="1" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 1</li>
                <li data-id="2" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 2</li>
                <li data-id="3" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Test 3</li>

            </ul>

        </div>

        <div class="modal-footer">

          <button id="save-reorder" type="button" class="btn btn-primary">Save</button>

        </div>

      </div>
    </div>
 </div>
 <a href="javascript://" id="target" >Open Modal</a>
    <script type="text/javascript">

$(document).ready(function(){

     $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();


});
$( "#target" ).click(function() {
   $("#settingsModal").modal('show');
});

</script>