简体   繁体   English

简单的JQuery拖放根本不起作用

[英]Simple JQuery Drag and Drop not working at all

I am new to JQuery stuff ,but this is ridiculous ,i cant do drag and drop work 我是JQuery的新手,但这太荒谬了,我无法进行拖放工作

.php file .php文件

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">      
    <title>PHP Test</title>
  </head>
  <body>
    <span id="drag">Drag me</span>

    <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
    <script type="text/javascript" src="js/drag.js"></script>
    <script type="text/javascript" src="js/jquery-ui.js"></script>
  </body>
</html>

my drag js file 我的拖动js文件

$(document).ready(function() {
    $('#drag').draggable();
});

By the way, do i need to have JQuery UI to make drag and drop stuff? 顺便说一句,我是否需要JQuery UI进行拖放操作?

Thank you 谢谢

The draggable() function requires jQueryUI to work. draggable()函数需要jQueryUI才能工作。 After including jQueryUI your code works fine. 包含jQueryUI之后,您的代码可以正常工作。

$('#drag').draggable();

http://codepen.io/tejzpr/pen/raXqKz http://codepen.io/tejzpr/pen/raXqKz

You should include the libraries in the correct order: 您应该以正确的顺序包含库:

<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/drag.js"></script>

Your custom code (drag.js) should be last, after jquery and jquery-ui have been loaded. 在加载了jquery和jquery-ui之后,您的自定义代码(drag.js)应该位于最后。

I would use cdn to save on speed and resources, and also be sure that you have a working copy. 我会使用CDN来节省速度和资源,并且还要确保您具有工作副本。 The order was probably your issue, however, as people mentioned above. 如上所述,订单可能是您的问题。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script>

You should first load UI script and use it after. 您应该首先加载UI脚本,然后再使用它。

 <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
 <script type="text/javascript" src="js/jquery-ui.js"></script>
 <script type="text/javascript" src="js/drag.js"></script>

Important: don't forget jQuery 2.* browser compatibility: https://jquery.com/download/#jquery-2-x It doesn't support IE 8 or earlier! 重要提示:不要忘记jQuery 2. *浏览器兼容性: https : //jquery.com/download/#jquery-2-x它不支持IE 8或更早版本!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM