Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
无法拖动jquery_Jquery_Drag - Fatal编程技术网

无法拖动jquery

无法拖动jquery,jquery,drag,Jquery,Drag,我使用这个函数进行拖放。在mousedown事件上调用此函数。当我第一次按下鼠标时,它不起作用,但在第二次按下鼠标时,它工作得非常好 我怎样才能让它第一次工作 function DivMouseDown(id) { alert("id:" +id); //alert(" i m in DivMouseDown"); try { jQuery('#'+ id).draggable({ opacity: 0.5, revert: 'invalid', drag:fun

我使用这个函数进行拖放。在mousedown事件上调用此函数。当我第一次按下鼠标时,它不起作用,但在第二次按下鼠标时,它工作得非常好

我怎样才能让它第一次工作

 function  DivMouseDown(id)
{
 alert("id:" +id);
//alert(" i m in DivMouseDown");
try
{

 jQuery('#'+ id).draggable({
   opacity:  0.5,
   revert: 'invalid',
    drag:function(ev,ui)
    {
    //alert("i m draggable");
    }
 });
}

catch (e)
{

 alert ("exception in DIVmouse down: "+ e);
}

一旦DOM就绪,就应该调用init函数

function initDivMouseDown(id)
{ 
    try {
        jQuery('#'+ id).draggable({ 
            opacity: 0.5, 
            revert: 'invalid', 
            drag:function(ev,ui) {
                // ADDED DIV ID HERE 
                alert($(this).attr('id') + " is being dragged");
            } 
        }); 
    } catch (e) {
        alert ("exception in DIVmouse down: "+ e); 
    }
}

jQuery(document).ready(function() {
    initDivMouseDown("my_div");
});

您将在何处添加mousedown事件?它是在您调用“draggable”之后添加的吗?