2012-10-17 52 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> 
相關問題