表格行中单元格的 jQuery 可放置选择器
我在找出解决此问题的正确选择器语法时遇到一些麻烦,希望得到一些帮助。
所以,我有一个有五列的表。在每一行的每个单元格中,我都有 DIV 元素和一个名为 MyClass 的类。我已将 MyClass 对象设置为可拖动,现在我需要设置适当的放置目标。我希望该行中的任何单元格都存在具有 MyClass 的元素(第一列除外),但仅限于该元素存在的行(它不应该能够被删除到其上方或下方的行列中)。
我希望这是有道理的。任何人都知道正确的语法是什么?下面是我目前所做的工作,但它不太正确,因为它允许放置在上方或下方的行中。
$(".MyClass").closest("tr").children(":not('.column-1')").droppable({ ... });
I'm having some trouble figuring out the right selector syntax for this problem and would appreciate some assistance.
So, I have a table that has five columns. In each row, in each cell, I have DIV elements with a class called MyClass. I've setup objects of MyClass to be draggable, and now I need to setup the appropriate drop targets. I would like for any cells in the row that an element with MyClass exists, except the first column, but ONLY for the row in which the element exists (it should not be able to be dropped in columns of rows above or below it).
I hope that makes sense. Anyone have any ideas what would be the correct syntax for that? Below is what I currently have working, but it's not quite right, because it allows dropping in rows above or below.
$(".MyClass").closest("tr").children(":not('.column-1')").droppable({ ... });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将函数传递给
accept
选项 < code>.droppable() 因此它只接受同一行中的那些元素,如下所示:
在函数中
draggable
是 jQuery 对象这就是可拖动的,我们只是使用$.contains()
查看.parentNode
()是否包含该可拖动...意味着您的
正在尝试从这一排掉落。
您可以在此处进行测试。
You can pass a function to the
accept
option for.droppable()
so it only accepts those<div>
elements in the same row, like this:In the function
draggable
is the jQuery object that is the draggable, we're just using$.contains()
to see if the.parentNode
(the<tr>
) contains that draggable...meaning the<div>
you're trying to drop came from this row.You can test it out here.