【问题标题】:Simulate click-and-hold模拟点击并按住
【发布时间】:2018-11-07 10:45:48
【问题描述】:

非常愚蠢的问题,但在这里找不到答案。

我想在 onmouseover 事件上对元素执行单击并按住(我想它是 mousedown 或可拖动,但对我来说不能正常工作)。

提前谢谢你!

【问题讨论】:

标签: jquery


【解决方案1】:

您好,欢迎来到 Stack Overflow。

如果您使用 jQuery 并且对此感到满意,jQueryUI 提供了一个库,可以让您根据要求执行单击和拖动操作。

Draggable Droppable

一个实际的例子如下:

  // Include your necessary files in your HEAD document.
  <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>

在您的 HTML 中包含以下内容:

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

【讨论】:

    猜你喜欢
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多