0

我想拖放带有文本的简单 div,并在我放下它时调整它的大小。我必须使用 jQuery,但我从不使用它。知道我在 Head 内容中有这样的代码:

<script src="Scripts/jquery.ui.draggable.js" type="text/javascript"></script> 
<script src="Scripts/jquery.ui.core.js" type="text/javascript"></script> 
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
<script type="text/javascript">
    $(function () {
        $("#d1").draggable();
    });
</script> 

     <div id="d1" style="width:100px; height:100px;"> 
  <p>Move This Div</p>
</div>

起初我想尝试移动这个 div,但不能移动它,我不知道为什么?之后我想尝试将它放在桌子上,并调整它的大小。请你提供一些有用的例子或你自己的例子.谢谢你 PS实际上我应该在桌子上移动 ASP.NET Web 窗体的控件

4

2 回答 2

2

你需要先加载 jquery 库,所以代码看起来像这样:

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
<script src="Scripts/jquery.ui.core.js" type="text/javascript"></script> 
<script src="Scripts/jquery.ui.draggable.js" type="text/javascript"></script> 

<script type="text/javascript">
    $(function () {
        $("#d1").draggable();
    });
</script> 
于 2012-10-17T13:23:07.483 回答
1

这是一个小例子:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#d1").draggable();
            $("#droppable").droppable({
                drop: function (event, ui) {
                    $(this).width(ui.draggable.width());
                    $(this).height(ui.draggable.height());
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="d1" style="width:100px; height:100px; border: solid 1px silver;">  
            <p>Move This Div</p> 
        </div>
        <table border="1">
            <tr>
                <td id="droppable" style="width: 200px; height: 200px;">
                    One
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
于 2012-10-17T15:21:03.703 回答