Javascript 如何在我的情况下禁用拖动功能?
我想停止Javascript 如何在我的情况下禁用拖动功能?,javascript,jquery,html,css,jquery-ui,Javascript,Jquery,Html,Css,Jquery Ui,我想停止可拖动方法中的拖动功能 $('#dragitem').draggable({ scroll : false, drag: function(event, ui){ //a if statement if(….){ //I want to stop the dragging here.
可拖动
方法中的拖动
功能
$('#dragitem').draggable({
scroll : false,
drag: function(event, ui){
//a if statement
if(….){
//I want to stop the dragging here.
}
}
});
有没有办法在拖动功能中停止拖动
?谢谢你的帮助 试试看:
$("#dragitem").draggable({ disabled: true });
试试这个:
$('#dragitem').draggable({
scroll : false,
drag: function(event, ui){
//a if statement
if(….){
//I want to stop the dragging here.
event.preventDefault();
}
}
});
我以前也遇到过这种情况,由于缺乏更好的解决方案,我在这里触发了
mouseup
事件:
drag: function(event, ui){
if(true) {
// stop dragging
$(document).trigger('mouseup');
}
}
您是否尝试过
返回false代码>?尝试将其添加到该块中。这应该会结束函数。@Luxelin不,它不起作用。你让它起作用了吗?如果不起作用,请尝试e.stopPropogation()我想你的意思是event.stopPropogation()代码>?据我所知,您的代码中没有定义e
。为什么需要event.stopPropogation()
?这里没有来自父节点的事件。只需preventDefault()