久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 jQuery UI 拖放:更改拖放的元素

Using jQuery UI drag-and-drop: changing the dragged element on drop(使用 jQuery UI 拖放:更改拖放的元素)
本文介紹了使用 jQuery UI 拖放:更改拖放的元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在使用 jQuery UI 可拖動和可放置元素時,如何在放置時更改拖放元素?我正在嘗試將一個 DIV 拖到另一個可排序的 DIV.在放置時,我想更改放置的 DIV 上的類并更改其 innerHTML 內容.

When using jQuery UI draggables and droppables, how do you change the dragged-and-dropped element on drop? I am trying to drag one DIV to another sortable DIV. On drop, I'd like to change the classes on the dropped DIV and change its innerHTML content.

閱讀各種 StackOverflow 問題后,我的代碼如下所示:

After reading various StackOverflow questions, my code looks like this:

$(".column").droppable({
  accept: '.element-dragging', 
    drop: function(event, ui) {
        if ($(ui.draggable).hasClass("elemtxt")) {
            $(ui.draggable).replaceWith('<div class="element element-txt">This text box has been added!</div>');
        }
    }
})

它不適合我.:-(

我的代碼的完整副本位于 http://www.marteki.com/jquery/bugkilling.php.

A full copy of my code is located at http://www.marteki.com/jquery/bugkilling.php.

推薦答案

從您提供的鏈接中獲取完整的 javascript 代碼,您可以進行如下更改以使其工作:

Taking the full javascript code from the link you gave, you can change it as follows to make it work:

$(function() {
    $(".elementbar div").draggable({
        connectToSortable: '.column',
        cursor: 'move',
        cursorAt: { top: 0, left: 0 },
        helper: 'clone',
        revert: 'invalid'
    });
    $(".elementbar div, .elementbar div img").disableSelection();
    $(".column").sortable({
        connectWith: '.column',
        cursor: 'move', 
        cursorAt: { top: 0, left: 0 }, 
        placeholder: 'ui-sortable-placeholder',
        tolerance: 'pointer',
        stop: function(event, ui) {
            if (ui.item.hasClass("elemtxt")) {
                ui.item.replaceWith('<div class="element element-txt">This text box has been added!</div>');
            }
        }
    });
    $(".element").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all");
});

有幾個問題:

  1. drop 事件(您在問題中顯示的)沒有觸發,因為您沒有接受正確的內容.
  2. 如果您同時擁有 .sortable.droppable 你最終會觸發奇怪的雙重事件.無論如何,這都是不必要的,因為您可以有效地從 sortable 的事件中獲取 drop 事件,因為您已將它與可拖動對象鏈接.
  1. The drop event (that you show in your question) wasn't firing because you weren't accepting the right content.
  2. If you have both .sortable & .droppable you end up with weird double events firing. This is unnecessary anyway, since you can effectively grab the drop event from sortable's events given that you've linked it with the draggable.

還有一點需要注意 - 使用 sortable 的 receive 事件而不是 stop 會更好(因為每次任何排序停止和接收時都會觸發 stop當您將新項目放入排序列表時會特別觸發),但它無法正常工作,因為 item 尚未添加到可排序列表中,所以您沒有能夠在那個時候改變它.它在停止時可以正常工作,因為其他可排序項目都沒有 elemtxt 類.

One other thing to note - it would have been nicer to use the sortable's receive event instead of stop (since stop gets fired every time any sorting stops & receive is specifically there to fire when you drop a new item into the sort list), but it doesn't work properly because the item hasn't yet been added to the sortable list, so you aren't able to change it at that point. It works ok on stop simply because none of the other sortable items have the elemtxt class.

這篇關于使用 jQuery UI 拖放:更改拖放的元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 亚洲免费精品 | 污免费网站 | 精品久久一区 | 中文字幕在线一区 | 国产精品久久久久久久久久免费看 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 欧美一区二区在线 | www亚洲精品 | 欧美美女一区二区 | 91不卡 | 国产精品精品 | 欧美一区2区三区4区公司二百 | 国产精品无码久久久久 | 欧美亚洲国产日韩 | 久久久久久av | 免费午夜电影 | 男女羞羞免费网站 | 99热精品在线观看 | 国户精品久久久久久久久久久不卡 | 91久久久久久久久 | 岛国毛片在线观看 | 日韩美女在线看免费观看 | 亚洲国产福利视频 | 97av视频 | 欧美精品在线一区 | 精品久久久久久久久久久院品网 | av中文字幕网 | 成人精品啪啪欧美成 | 日本免费一区二区三区视频 | 91麻豆精品国产91久久久久久久久 | 欧美一区二区 | 亚洲成人三区 | 一级片免费在线观看 | av激情影院| 国产精品激情小视频 | 古装三级在线播放 | 国产精品一区二区三级 | 日韩精品免费 | 免费一区二区三区 | 日韩精品久久久久 | 欧美一级做性受免费大片免费 |