【问题标题】:How drag & drop and resize comnponents dynamically ASP.NET?如何在 ASP.NET 中动态拖放和调整组件大小?
【发布时间】:2012-10-17 23:21:03
【问题描述】:

我想拖放带有文本的简单 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,但不能移动它,我不知道为什么?之后我想尝试将它放在桌子上,并调整它的大小。请你提供一些有用的例子或你自己的例子。谢谢你 P.S.其实我应该把 ASP.NET Web Form 的控件移到桌子上

【问题讨论】:

    标签: c# jquery asp.net drag-and-drop


    【解决方案1】:

    你需要先加载 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> 
    

    【讨论】:

    • 您好,我已经加载了库,解压缩,并将这 3 个文件复制到我的项目 ASP.NET
    【解决方案2】:

    这是一个小例子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 2021-12-28
      • 1970-01-01
      • 2016-06-13
      相关资源
      最近更新 更多