Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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_Css_Asp.net Mvc - Fatal编程技术网

Jquery 禁用主体外部的可拖动元素

Jquery 禁用主体外部的可拖动元素,jquery,css,asp.net-mvc,Jquery,Css,Asp.net Mvc,当我拖动一个元素时。它从身体的外部进入。如何在体内禁用或使其可拖动 <div id="drag" style="background-color:red;"> <fieldset> <h2 class="fs-title">Login</h2> <h3 class="fs-subtitle"></h3> <input na

当我拖动一个元素时。它从身体的外部进入。如何在体内禁用或使其可拖动

    <div id="drag" style="background-color:red;">
        <fieldset>
            <h2 class="fs-title">Login</h2>
            <h3 class="fs-subtitle"></h3>

            <input name="UserName" type="text" placeholder="Username">
            <input name="Password" type="Password" placeholder="Password">
            <input type="button" name="next" class="next action-button" value="New User" />

            <input type="submit" name="next" class="nexts action-login" value="Log in" />
        </fieldset>

    </div>
}

<script type="text/javascript">
    $(function () {
        $("#drag").draggable();
    });
</script>

    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
        @Scripts.Render("~/bundles/jqueryui")
    }

登录
}
$(函数(){
$(“#拖动”).draggable();
});
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
@Scripts.Render(“~/bundles/jqueryui”)
}

这将禁止
#拖动
离开身体:

$("#drag").draggable({containment:'body'});

您必须使用
包容
约束可拖动:

$("#drag").draggable({ containment: "parent" });
有关详细信息:

或者,如果你不想让拖拽的东西离开你的身体,那么:

 $("#drag").draggable({ containment: "body" });

当我拖动一个元素时,左和右都可以…但它在窗口上走得很远height@SirushtiDedDragable应该在你的身体内,但如果你的问题仍然存在,那么遵循此链接,它将对你有效。。