第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 JQuery 在使用可拖放和可拖放之后插入和追加?

如何使用 JQuery 在使用可拖放和可拖放之后插入和追加?

一只甜甜圈 2022-05-26 11:18:54
我正在嘗試構(gòu)建一個(gè) Bootstrap 編輯器。我有一個(gè)<li>假定的 Bootstrap 類或工具的菜單,無論如何。<li>添加新部分和<li>添加一些工具是有區(qū)別的。添加一個(gè)我在之后使用插入的部分并添加我使用附加的工具。這里的部分是“當(dāng)前”或“新”。jQuery<script>    $(function () {        $(".draggable").draggable({            helper: "clone",            end: function (e, ui) {                const Holded_ItemID = ui.draggable.attr("id");                if (Holded_ItemID == 'Sec') {                    $("li").removeClass("NewSection");                     $(ui.helper).addClass("NewSection");                }            }        });        $("#droppable").droppable({            drop: function (e, ui) {                const Holded_ItemID = ui.draggable.attr("id");                if (Holded_ItemID == 'Sec') {                //to insert new section after current section                $(this).children().last().insertAfter($(ui.draggable).clone());                }                else                {                //to add elemnt inside the new section                    $('.NewSection').append($(ui.draggable).clone());                };            }        });    });</script>HTML    <ul>        <li id="Sec" class="draggable">add new section</li>        <li class="draggable ui-widget-content">add new grid</li>        <li class="draggable ui-widget-content">add new button</li>        <li class="draggable ui-widget-content">add new Image</li>        <li class="draggable ui-widget-content">add new card</li>        <li class="draggable ui-widget-content">add new media objects</li>    </ul>    <div class="droppable ui-widget-header">      <p>Area Of web design</p>    </div>CSS  <style>  .draggable { width: 170px; height: 20px; border:1px dotted black; padding: 1px 1px 1px 10px; margin:3px; }  .droppable { width: 500px; height: 300px; padding: 0.5em; float: left; margin: 10px; padding:10px; background-color:antiquewhite; }  </style>簡(jiǎn)單地說,我無法將 li 菜單中的任何內(nèi)容添加到可放置區(qū)域中。為什么,我的代碼有什么問題?
查看完整描述

1 回答

?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

幾點(diǎn)注意事項(xiàng):

  • 因?yàn)?code>draggable({})你必須使用stop()事件而不是end。

  • 我曾經(jīng)ui.helper訪問拖動(dòng)的元素。

  • 而不是$(this).children().last().insertAfter我使用的只是附加,不知道你為什么使用它,所以你可能想根據(jù)需要修改我的更改。

我想這就是你想要的

$(function () {

  $(".draggable").draggable({

    helper: "clone",

    stop: function (e, ui) {

      //console.log(ui.helper[0]);

      const Holded_ItemID = $(ui.helper[0]).attr("id");

      if (Holded_ItemID == 'Sec') {

        $("li").removeClass("NewSection"); 

        $(ui.helper[0]).addClass("NewSection");

      }

    }

  });


  $("#droppable").droppable({

    drop: function (e, ui) {

      const Holded_ItemID = $(ui.draggable[0]).attr("id");

      if (Holded_ItemID == 'Sec') {

      //to insert new section after current section

        $("#droppable").append(ui.draggable[0])

        //$(this).children().last().insertAfter($(ui.draggable).clone());

      } else {

        //to add elemnt inside the new section

        $("#droppable").append($(ui.draggable[0]).clone());

      };

    }

  });

});

.draggable { width: 170px; height: 20px; border:1px dotted black; padding: 1px 1px 1px 10px; margin:3px; }

.droppable { width: 500px; height: 300px; padding: 0.5em; float: left; margin: 10px; padding:10px; background-color:antiquewhite; }

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<ul>

    <li id="Sec" class="draggable">add new section</li>

    <li class="draggable ui-widget-content">add new grid</li>

    <li class="draggable ui-widget-content">add new button</li>

    <li class="draggable ui-widget-content">add new Image</li>

    <li class="draggable ui-widget-content">add new card</li>

    <li class="draggable ui-widget-content">add new media objects</li>

</ul>


<div id="droppable" class="droppable ui-widget-header">

  <p>Area Of web design</p>

</div>


查看完整回答
反對(duì) 回復(fù) 2022-05-26
  • 1 回答
  • 0 關(guān)注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)