如何拖拽动态删除和调整comnponents ASP.NET?

时间:2012-10-17 13:17:54

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

我想拖放带有文本的简单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.Actually我应该在表

上移动ASP.NET Web Form的控件

2 个答案:

答案 0 :(得分: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> 

答案 1 :(得分: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>
相关问题