Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
Javascript jquerydrag&;Drop:将元素从li更改为div并返回_Javascript_Jquery_Jquery Ui_Draggable_Droppable - Fatal编程技术网

Javascript jquerydrag&;Drop:将元素从li更改为div并返回

Javascript jquerydrag&;Drop:将元素从li更改为div并返回,javascript,jquery,jquery-ui,draggable,droppable,Javascript,Jquery,Jquery Ui,Draggable,Droppable,我正在尝试以下方法: 第一阶段: 在下拉菜单中,将可拖动元素从li更改为div 将可拖动元素移动到画布内部 第2阶段: 在#imagelist 将可拖动元素移动到#imagelist Js: Html: 拖放时不应丢失的内容 拖放时不应丢失的内容 有人能帮我吗?您可以创建一个新函数来更改元素类型-我认为您需要: (function($) { $.fn.changeElementType = function(newType) { var attrs = {};

我正在尝试以下方法:

第一阶段:

  • 在下拉菜单中,将可拖动元素从li更改为div
  • 将可拖动元素移动到画布内部
  • 第2阶段:

  • #imagelist
  • 将可拖动元素移动到#imagelist
  • Js:

    Html:

    
    
    • 拖放时不应丢失的内容
    拖放时不应丢失的内容

    有人能帮我吗?

    您可以创建一个新函数来更改元素类型-我认为您需要:

    (function($) {
        $.fn.changeElementType = function(newType) {
            var attrs = {};
    
            $.each(this[0].attributes, function(idx, attr) {
                attrs[attr.nodeName] = attr.nodeValue;
            });
    
            this.replaceWith(function() {
                return $("<" + newType + "/>", attrs).append($(this).contents());
            });
        };
    })(jQuery);
    
    (函数($){
    $.fn.changeElementType=函数(新类型){
    var attrs={};
    $.each(此[0]。属性,函数(idx,attr){
    attrs[attr.nodeName]=attr.nodeValue;
    });
    this.replaceWith(函数(){
    返回$(“”,attrs.append($(this.contents());
    });
    };
    })(jQuery);
    

    <div id="listwrapper">
      <ul id="imagelist">
         <li class="draggable>Content that should not be lost on drag/drop</li>
         <li class=" draggable>Content that should not be lost on drag/drop</li>
      </ul>
    </div>
    <div id="canvas">
      <div class="draggable">Content that should not be lost on drag/drop</div>
    </div>
    
    (function($) {
        $.fn.changeElementType = function(newType) {
            var attrs = {};
    
            $.each(this[0].attributes, function(idx, attr) {
                attrs[attr.nodeName] = attr.nodeValue;
            });
    
            this.replaceWith(function() {
                return $("<" + newType + "/>", attrs).append($(this).contents());
            });
        };
    })(jQuery);