JQuery 拖放和排序

发布于 2024-11-17 05:54:06 字数 2011 浏览 3 评论 0原文

我有一张桌子,有左栏和右栏。在 cols 内部,有一些来自 PHP 循环的小表(作为元素)。 我希望能够将元素从左列拖放到右列,并且还可以更改列本身内部的排序。对我来说太难了!

这是我的代码: HTML 部分(左栏但右栏相同)

<style>
.deplace{
cursor:move;
}
</style>

<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<td id="leftMenu" valign="top" style="width:180px;height:800px;border:1px solid black">
<?php

while($rowg = mysql_fetch_assoc($sqlg)){

echo '<table width="100%" cellpadding="5" cellspacing="2" 
style="background-color:#CCC;border: 1px solid black;height:100px" 
class="deplace" id="left_'.$rowg['id'].'" modulename="'.modif_nom($rowg['module']).'"     sourceid="'.$rowg['id'].'">

echo '<tr><td" align="center" style="width:100%">'.$rowg['module'].'</td></tr>';

echo '</table>';
}
?>
</td></tr></table>

和 JS 代码:

<script language="javascript" type="text/javascript">
$(document).ready(function() {  //

$('#leftMenu').Sortable({
  //revert: true,
  accept: 'deplace',
  axis : 'vertically',

  onchange: function(event, ui) { 
    serial = $.SortSerialize('leftMenu');
    $.ajax ( {
    url : "xhr.php?source=leftMenu",
    type : "get",
    data : serial.hash,
    success: function(data){alert(data);}
    });

  }
});

$('#rightMenu').Sortable({
  //revert: true,
  accept: 'deplace',
  axis : 'vertically',

  onchange: function(event, ui) { 
    serial = $.SortSerialize('rightMenu');
    $.ajax ( {
    url : "xhr.php?source=rightMenu",
    type : "get",
    data : serial.hash,
    success: function(data){alert(data);}
    });

  }
});
//only the functions to move the tables from left to right
$('#rightMenu').draggable({
    revert:false,
    helper:'original',

});

$('#leftMenu').droppable({
    over:function(event, ui){                     
    alert('dropped');
    }
});
});
</script>

所以,就像这样,功能之间似乎存在冲突。如果我只允许排序函数,那没问题,但我不能在接收器列中执行任何操作,并且我想向 PHP 发送请求以更新 mysql 表。

非常感谢您的帮助!

I have a table with left and right col. Inside the cols, some small tables (as elements) from PHP loop.
I would like to make possible to drag and drop the elements from left to right cols AND also change the sort inside the col itself. Very hard for me !

Here's my code :
HTML part (left col but the right one is the same)

<style>
.deplace{
cursor:move;
}
</style>

<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<td id="leftMenu" valign="top" style="width:180px;height:800px;border:1px solid black">
<?php

while($rowg = mysql_fetch_assoc($sqlg)){

echo '<table width="100%" cellpadding="5" cellspacing="2" 
style="background-color:#CCC;border: 1px solid black;height:100px" 
class="deplace" id="left_'.$rowg['id'].'" modulename="'.modif_nom($rowg['module']).'"     sourceid="'.$rowg['id'].'">

echo '<tr><td" align="center" style="width:100%">'.$rowg['module'].'</td></tr>';

echo '</table>';
}
?>
</td></tr></table>

And the JS code :

<script language="javascript" type="text/javascript">
$(document).ready(function() {  //

$('#leftMenu').Sortable({
  //revert: true,
  accept: 'deplace',
  axis : 'vertically',

  onchange: function(event, ui) { 
    serial = $.SortSerialize('leftMenu');
    $.ajax ( {
    url : "xhr.php?source=leftMenu",
    type : "get",
    data : serial.hash,
    success: function(data){alert(data);}
    });

  }
});

$('#rightMenu').Sortable({
  //revert: true,
  accept: 'deplace',
  axis : 'vertically',

  onchange: function(event, ui) { 
    serial = $.SortSerialize('rightMenu');
    $.ajax ( {
    url : "xhr.php?source=rightMenu",
    type : "get",
    data : serial.hash,
    success: function(data){alert(data);}
    });

  }
});
//only the functions to move the tables from left to right
$('#rightMenu').draggable({
    revert:false,
    helper:'original',

});

$('#leftMenu').droppable({
    over:function(event, ui){                     
    alert('dropped');
    }
});
});
</script>

So, like that, it seems there's a conflict between the functions. If I only let the sortable functions, it's OK but I can't do anything in the receiver col and I would like to send a request to PHP to update a mysql table.

Thanks a lot for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-11-24 05:54:06

您的代码存在一些问题:

  • Sortable 是小写
  • SortSerialize 不存在,我认为您的意思是 sortable("serialize")
  • $('# rightMenu').draggable 应该更改为 $('#rightMenu').children().draggable 因为你想拖动菜单内的元素

看看 jQuery UI 可排序文档 也是如此。

There are a few issues with your code:

  • Sortable is lower-case
  • SortSerialize does not exist, I think you mean sortable("serialize")
  • $('#rightMenu').draggable should be changed to $('#rightMenu').children().draggable because you want to drag the elements inside the menu

Have a look at the jQuery UI Sortable doc too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文