开发者

Jquery delete element by double click

开发者 https://www.devze.com 2023-03-23 01:29 出处:网络
Jquery drag and drop question I want to delete some elements that are inside a div container. My script is like this : i drag the element into #deleteArea and the element is out. The 开发者_高级运维s

Jquery drag and drop question

I want to delete some elements that are inside a div container. My script is like this : i drag the element into #deleteArea and the element is out. The 开发者_高级运维script :

  $("#deleteArea").droppable
     ({
         drop: function(event, ui) { 
            alert('in');
         deleteImage(ui.draggable,ui.helper); 
         }, 
         over: function() {
                   $(this).css('backgroundColor', '#cedae3');
            },
             out: function() {
                    $(this).css('backgroundColor', '#ffffff');
            },
        });

and

function deleteImage($draggable,$helper)
         {
         params = 'id=' + $draggable.attr('id');

         $.ajax({
         url: 'delete.php',
         type: 'POST',
         data: params,
          success: function(msg){  
                                   }
         });
         $helper.effect('transfer', { to: '#deleteArea', className: 'ui-effects-transfer' },500);
         $draggable.hide();
         }

Now i want to remove elements just by double click. I try starting from the script above this little code :

  $('.produse').dblclick(function(event, ui) { 
            alert('in');
         deleteImage(ui.draggable,ui.helper); 
         });

but i recive "ui is undefined" and i dont know what to do. please help


You are not passing parameters to the click handler correctly.

In this piece of code:

$('.produse').dblclick(function(event, ui) { 
        alert('in');
     deleteImage(ui.draggable,ui.helper); 
     });

you have not declared the parameters to the anonymous function appropriately. If you look at the jQuery doc for .dblclick(), there are two ways of calling it:

.dblclick(handler(event))

or

.dblclick([eventData,] handler(event))

You are using neither of those.

If you want to pass some data to the dlbclick handler, it would work like this:

$('.produse').dblclick({uiData: ui}, function(event) { 
        alert('in');
     deleteImage(event.data.uiData.draggable, event.data.uiData.helper); 
     });

You can see it in action here: http://jsfiddle.net/jfriend00/NUU8s/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号