2012-10-17 50 views
0

我想拖放文本的简单div,并调整它的大小,当我放下它时。 我必须使用jQuery,但我从来没有使用它。 权利知道我有这样的代码在头内容:如何在ASP.NET中动态拖放和调整组件大小?

<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,但不能移动它,我不知道为什么?之后,我想尝试把它放在桌子上,并调整它。请你可以提供一些有用的例子或你自己的例子。谢谢 PSA其实我应该移动ASP.NET Web Form的控件在表

回答

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> 
+0

您好我已加载库,解压缩它,这3个文件复制到我的项目ASP.NET – BeginerDummy

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> 
相关问题