當我拖動div
並將其放在另一個位置時,我得到該div的座標(例如:左,右,頂部在CSS中)並使用Ajax請求我的控制器將其保存在數據庫中 例如鏈接 jsfiddle.net/qPw92使用jQuery ui庫獲取元素的拖動位置
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<style>
.draggable {
width: 150px;
min-height: 150px;
padding: 0.5em;
border:1px solid black;
overflow-wrap: break-word;
}
</style>
<script>
$(function() {
$('.draggable').draggable({
var data={
// Get some dives coordinates
};
$.ajax({
url: "<?php echo base_url();?>index.php/pages/getinfo/",
data: data,
type: 'POST',
success: function(result){
//alert(result);
$("#ajaxResponce").html(result);
}
});
});
});
</script>
</head>
<body>
<div class="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
</body>
</html>
首先,你的代碼有什麼問題?其次,請花時間格式化代碼,以便在您的問題中可讀。 –