如何检查一个元素是否可拖放、可拖放或其他“可能”?

时间:2022-12-06 15:53:58

I've got a bunch of elements with jQuery. Some are draggable, some are droppable and some are both. How can I detect if an element is draggable or droppable?

我有一些jQuery元素。有些是可拖的,有些是可拖的,有些两者都是。我如何检测一个元素是可拖动的还是可删除的?

4 个解决方案

#1


26  

You could also use jQuery data() like this..

您还可以像这样使用jQuery数据()。

if ($(elem).data('draggable')) {
        alert("yes");
}
else {
        alert("no");
}

if ($(elem).data('fooable')) {
        alert("yes");
}
else {
        alert("no");
} 

See it here: http://bootply.com/60153

看到这里:http://bootply.com/60153

#2


14  

This works for me with JQuery 1.10.2

这在JQuery 1.10.2中适用

if ($("el").data('uiDraggable')){ //or uiDroppable
   alert("draggable")
} else {
   alert("not draggable")
}

Alternatively it is possible to invoke .data() method without argument

或者,也可以不带参数地调用.data()方法

$("el").data()

That should print something like

那应该打印出来。

Object {uiDraggable: $.(anonymous function).(anonymous function)}

{ uiDraggable:$对象。(匿名函数)。(匿名函数)}

where you can see object properties.

你可以看到对象属性。

#3


5  

For draggable elements:

为可拖动的元素:

$(elem).is('.ui-draggable')

or you could filter, or just select $('.ui-draggable');.

或者您可以过滤,或者选择$('.ui-draggable');

For droppable, you would use .ui-droppable, resizable is .ui-resizable, selectable is .ui-selectable for the container although the items you select are .ui-selectee, sortable is .ui-sortable for the container.

对于droppable,可以使用。ui-droppable, resizable。ui-resizable, seltible是。ui- selableforcontainer,尽管你选择的项目是。ui-selectee, sortable是。ui-sortable。

#4


0  

I use Modernizr:

我用Modernizr:

if (Modernizr.draganddrop) {
// use drag and drop
}

#1


26  

You could also use jQuery data() like this..

您还可以像这样使用jQuery数据()。

if ($(elem).data('draggable')) {
        alert("yes");
}
else {
        alert("no");
}

if ($(elem).data('fooable')) {
        alert("yes");
}
else {
        alert("no");
} 

See it here: http://bootply.com/60153

看到这里:http://bootply.com/60153

#2


14  

This works for me with JQuery 1.10.2

这在JQuery 1.10.2中适用

if ($("el").data('uiDraggable')){ //or uiDroppable
   alert("draggable")
} else {
   alert("not draggable")
}

Alternatively it is possible to invoke .data() method without argument

或者,也可以不带参数地调用.data()方法

$("el").data()

That should print something like

那应该打印出来。

Object {uiDraggable: $.(anonymous function).(anonymous function)}

{ uiDraggable:$对象。(匿名函数)。(匿名函数)}

where you can see object properties.

你可以看到对象属性。

#3


5  

For draggable elements:

为可拖动的元素:

$(elem).is('.ui-draggable')

or you could filter, or just select $('.ui-draggable');.

或者您可以过滤,或者选择$('.ui-draggable');

For droppable, you would use .ui-droppable, resizable is .ui-resizable, selectable is .ui-selectable for the container although the items you select are .ui-selectee, sortable is .ui-sortable for the container.

对于droppable,可以使用。ui-droppable, resizable。ui-resizable, seltible是。ui- selableforcontainer,尽管你选择的项目是。ui-selectee, sortable是。ui-sortable。

#4


0  

I use Modernizr:

我用Modernizr:

if (Modernizr.draganddrop) {
// use drag and drop
}