模拟点击并按住

时间:2018-11-07 10:45:49

标签: jquery

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

我想对onmouseover事件上的元素执行点击并按住(我想是将鼠标按下或拖动,但对我而言无法正常工作)。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您好,欢迎来到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>