Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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 如何在我的情况下禁用拖动功能?_Javascript_Jquery_Html_Css_Jquery Ui - Fatal编程技术网

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()