Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui jQuery UI可排序-如何替换现有项或根据位置插入新的可排序项_Jquery Ui_Jquery Ui Sortable_Jquery Ui Draggable - Fatal编程技术网

Jquery ui jQuery UI可排序-如何替换现有项或根据位置插入新的可排序项

Jquery ui jQuery UI可排序-如何替换现有项或根据位置插入新的可排序项,jquery-ui,jquery-ui-sortable,jquery-ui-draggable,Jquery Ui,Jquery Ui Sortable,Jquery Ui Draggable,我想实施以下措施: 我有一个源容器,其中填充了一个可拖动项的列表 我有一个目标可排序容器,其中填充了 与源项的类型相同 当我将项目从源拖放到目标时,我想决定如何使用可拖动(助手克隆): 在项目鼠标结束之前插入 替换项鼠标位于上方可以将替换视为删除和插入组合。简单地为每个项目添加一个删除按钮,这样用户就可以通过draggable手动删除然后插入,怎么样? <html> <head> <meta http-equiv="content-type" content="t

我想实施以下措施:

  • 我有一个源容器,其中填充了一个可拖动项的列表
  • 我有一个目标可排序容器,其中填充了 与源项的类型相同
  • 当我将项目从源拖放到目标时,我想决定如何使用可拖动(助手克隆):

    • 在项目鼠标结束之前插入

    • 替换项鼠标位于上方可以将替换视为删除和插入组合。简单地为每个项目添加一个删除按钮,这样用户就可以通过draggable手动删除然后插入,怎么样?
      <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
      
      <script type="text/javascript">
      function pageLoad() {
        $(function () {
      
          $( "#source .item" ).draggable({
            connectToSortable: '#target',
            cursor: 'move',
            helper: 'clone'
          }).disableSelection();
      
          $( "#target" ).sortable({
            // ----- remove item from container if dragged out ----
            receive: function (e, ui) { inout = 1; },
            over: function (e, ui) { inout = 1; },
            out: function (e, ui) { inout = 0; },
            beforeStop: function (e, ui) { if (inout == 0)  ui.item.remove(); },
            // ----------------------------------------------------
      
            dropOnEmpty: true,
            tolerance: 'pointer',
            placeholder: 'placeholder',
            cursor: 'move'
          }).disableSelection();
        });
      };
      </script>
      
      <style type="text/css">
      body {
          font-family: Arial;
      }
      .container {
          background-color: silver;
          padding: 5px;
      }
      .item {
          margin: 5px;
          padding: 3px;
          border: 1px dotted silver;
          background-color: white;
      }
      .placeholder {
          height: 1.5em;
      }
      </style>
      </head>
      
      <body>
      SOURCE
      <div id="source" class="container">
          <div class="item">draggable 1<br/>2<sup>nd</sup> line</div>
          <div class="item">draggable 2</div>
      </div>
      <br/>
      TARGET
      <div id="target" class="container">
          <div class="item">pre-filled 1</div>
          <div class="item">pre-filled 2</div>
      </div>
      </body>
      </html>