按键不能做的jQuery UI可拖动拖拽元素() [英] buttons can't made draggables by jQuery UI draggable()

查看:202
本文介绍了按键不能做的jQuery UI可拖动拖拽元素()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命名的 jQuery UI的拖拽元素样本默认说:

任何DOM元素上启用拖拽功能。

Enable draggable functionality on any DOM element.

但我不能让他们在按钮工作取值元素。

But I'm not able to make them work on buttons elements.

我修改了默认样品看起来像这样:

I modified the Default sample to look like this:

我刚换的div元素到一个按钮一个用键入=按钮

I just changed the div element to a button one with type="button":

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Draggable - Default functionality</title>
    <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
    <script src="../../jquery-1.9.1.js"></script>
    <script src="../../ui/jquery.ui.core.js"></script>
    <script src="../../ui/jquery.ui.widget.js"></script>
    <script src="../../ui/jquery.ui.mouse.js"></script>
    <script src="../../ui/jquery.ui.draggable.js"></script>
    <link rel="stylesheet" href="../demos.css">
    <style>
    #draggable { width: 150px; height: 150px; padding: 0.5em; }
    </style>
    <script>
    $(function() {
        $( "#draggable" ).draggable();
    });
    </script>
</head>
<body>

<button type="button" id="draggable" class="ui-widget-content">
    <p>Drag me around</p>
</button>

<div class="demo-description">
<p>Enable draggable functionality on any DOM element. Move the draggable object by clicking on it with the mouse and dragging it anywhere within the viewport.</p>
</div>
</body>
</html>

我怎样才能让一个按钮元素的拖拽元素功能工作的?

How I can make the draggables functionality work on a button element?

推荐答案

使用取消:假似乎为我工作

    $(function() {
    $( "#draggable" ).draggable({
        cancel: false
    });
});

的jsfiddle

我想没有取消只是触发按钮的默认click事件,并与取消你prevent默认click事件。

I guess without the cancel only the default click event of the button fires and with cancel you prevent the default click event.

这篇关于按键不能做的jQuery UI可拖动拖拽元素()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆