javascript - 使用 Jquery UI 放置后可拖动元素不再可拖动

标签 javascript jquery jquery-ui

下面是我的代码。

   <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Droppable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
  #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
    $( "#droppable" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
  } );
  </script>
</head>
<body>
 
<div id="draggable" class="ui-widget-content">
  <p>Drag me to my target</p>
</div>
 
<div id="droppable" class="ui-widget-header">
  <p>Drop here</p>
</div>
 
 
</body>
</html>

这里它将拖放到容器内。我想做的是在拖放之后不能再从拖放容器中拖动。如果有人知道解决方案,请帮助我解决这个问题。

最佳答案

您好,一旦拖放事件就禁用它。

$( "#draggable").draggable( '禁用' );

   <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Droppable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
  #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
    $( "#droppable" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
         $( "#draggable" ).draggable( 'disable' );
      }
    });
  } );
  </script>
</head>
<body>
 
<div id="draggable" class="ui-widget-content">
  <p>Drag me to my target</p>
</div>
 
<div id="droppable" class="ui-widget-header">
  <p>Drop here</p>
</div>
 
 
</body>
</html>

关于javascript - 使用 Jquery UI 放置后可拖动元素不再可拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277834/

相关文章:

javascript - 强制网页以 100% 缩放打开(在 IE8 中)

javascript - 拒绝获取不安全 header "ETag"

jquery - 无法使用 jQuery 从 DOM 访问 document.ready 元素?

javascript - Jquery Tab菜单滚动箭头

javascript - 在 CSS 网格布局中使用 em 或百分比

javascript - 如何在 iPhone 上使用 onclick

javascript - 如何为不同路径的js文件仅使用一个RequireJS配置文件?

javascript - 当光标离开输入框#select-or-enter-category时,此代码检查下拉列表中是否存在给定的输入

javascript - 如何垂直显示 <h1> 元素(每个字符换行)

jquery - Datepicker setDate 不再工作了?