ExtJS中的拖放組件是從Ext.dd.DragDrop繼承而來的,包括放置區域的組件Ext.dd.DDTarget,Ext.dd.DropZone,拖動塊組件Ext.dd.DD,Ext.dd.DDPRoxy,Ext.dd.DragSource。下面示例把Ext.dd.DragSource拖放到指定的區域Ext.dd.DDTarget中:
ExtJS拖放技術
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>ExtJS拖放技術</title>
<link rel="stylesheet" type="text/css"
href="../script/resources/css/ext-all.css" />
<script type="text/javascript" src="../script/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../script/ext-all.js"></script>
<style type="text/css">
.proxy {
background: #5eb0fd;
width: 100px;
height: 100px;
border:1px #fda95e solid;
text-align: center;
padding:10px;
font-size:12px;
}
.target {
width:200px;
height:200px;
background-color: #ea9d6a;
padding:10px;
font-size:12px;
}
</style>
<script type="text/javascript">
Ext.onReady(function(){
var proxy = new Ext.dd.DragSource('div-proxy', {group:'dd'});
proxy.afterDragDrop = function(target, e, id) {
alert('已接收proxy');
};
var target = new Ext.dd.DDTarget('div-target', 'dd');
});
</script>
</head>
<body>
<br>
<div id="div-proxy" class="proxy">
這是一個拖動塊,另外,也可以使用Ext.dd.DD,Ext.dd.DDProxy,Ext.dd.DragZone創建拖動塊
</div>
<hr />
<div id="div-target" class="target">
這裡是放置區域Ext.dd.DDTarget,另外也可以使用Ext.dd.DropZone創建放置區域
</div>
</body>
</html>