We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
是的,表格行可以上下滑动,但它很丑,因为它改变了表格的形状并使所有内容都跳跃。相反,在每个
td
中放置一个元素,例如p
或h2
等有意义的元素。至于实现表格滑动切换.. 将点击处理程序放在整个表格上可能
是最简单的,
.stopPropagation( )
和检查点击的内容。如果单击带有 colspan 的行中的 td,则关闭其中的
p
。如果它不是带有 colspan 的行中的 td,则关闭然后切换下一行的p
。将所有书面内容包装在
td
内的元素中非常重要,因为您永远不想slideUp
td
或tr
或者表格形状会改变!类似于:
尝试一下这个 jsFiddle 示例。
... 并尝试这个 jsFiddle 显示
+
--
的实现切换。HTML 只需要有几个
td
的交替行,然后是一个 colspan 的td
大于 1 的行。显然,您可以相当地调整细节容易地。HTML 看起来像这样:
Yes, a table row can slide up and down, but it's ugly since it changes the shape of the table and makes everything jump. Instead, put an element in each
td
, something that makes sense like ap
orh2
etc.As for implementing a table slide toggle...
It's probably simplest to put the click handler on the entire table,
.stopPropagation()
and check what was clicked.If a td in a row with a colspan is clicked, close the
p
in it. If it's not a td in a row with a colspan, then close then toggle the following row'sp
.It is essential to wrap all your written content in an element inside the
td
s, since you never want toslideUp
atd
ortr
or table shape will change!Something like:
Try it out with this jsFiddle example.
... and try out this jsFiddle showing implementation of a
+
--
toggle.The HTML just has to have alternating rows of several
td
s and then a row with atd
of a colspan greater than 1. You can obviously adjust the specifics quite easily.The HTML would look something like:
你可以这样做:
HTML
jQuery
请参阅 demo JSFiddle
You could do it like this:
HTML
jQuery
See a demo on JSFiddle
这取决于您的标记,但它肯定可以工作,我使用了以下内容:
jQuery
html
我处理它的方式是折叠行单元格内的特定元素,这样,在我的例子中,行会
slideUp()
因为段落被隐藏,并且仍然留下一个元素h2
供单击以重新显示内容。如果行完全倒塌,就没有明显的方法可以将其恢复原样。JS Bin 演示
正如 @Peter Ajtai 在评论中指出的,上述方法仅关注一个单元格(尽管是故意的)。要展开所有子
p
元素,可以使用以下方法:JS Bin 上的演示
It depends on your mark-up, but it can certainly be made to work, I used the following:
jQuery
html
The way I approached it is to collapse specific elements within the cells of the row, so that, in my case, the row would
slideUp()
as the paragraphs were hidden, and still leave an element,h2
to click on in order to re-show the content. If the row collapsed entirely there'd be no easily obvious way to bring it back.Demo at JS Bin
As @Peter Ajtai noted, in the comments, the above approach focuses on only one cell (though deliberately). To expand all the child
p
elements this would work:Demo at JS Bin
jQuery
HTML
这很像上面的例子。我发现在尝试实现该示例时,如果要展开的表格行在未展开时被单击,它将消失,并且它将不再可展开
要解决此问题,我只是删除了单击可展开元素向上滑动的功能并使其只能使用上面的表格行进行切换。
我还对 HTML 和相应的 jQuery 做了一些小的更改。
注意:我本来想发表评论,但目前还不允许发表评论,因此这篇文章很长。只是想发布此内容,因为我花了一些时间才弄清楚消失的表行发生了什么。
感谢 Peter Ajtai
jQuery
HTML
This is much like a previous example above. I found when trying to implement that example that if the table row to be expanded was clicked while it was not expanded it would disappear, and it would no longer be expandable
To fix that I simply removed the ability to click the expandable element for slide up and made it so that you can only toggle using the above table row.
I also made some minor changes to HTML and corresponding jQuery.
NOTE: I would have just made a comment but am not allowed to yet therefore the long post. Just wanted to post this as it took me a bit to figure out what was happening to the disappearing table row.
Credit to Peter Ajtai
回答你的问题,不。不过,这对于 div 来说是可能的。唯一的问题是,如果使用 div 而不是表来完成功能,会造成混乱。
To answer your question, no. That would be possible with div though. THe only question is would cause a hazzle if the functionality were done with div rather than tables.
好吧,我想说使用 DIV 而不是表,因为它会更容易(但使用表没有任何问题)。
我的方法是使用 jQuery.ajax 并从服务器请求更多数据,这样,所选的 DIV(或 TD,如果您使用表)将根据请求的内容自动扩展。
这样,它可以节省带宽并使其运行速度更快,因为您不必一次加载所有内容。仅在选择时才加载。
Well, I'd say use the DIV instead of table as it would be much easier (but there's nothing wrong with using tables).
My approach would be to use jQuery.ajax and request more data from server and that way, the selected DIV (or TD if you use table) will automatically expand based on requested content.
That way, it saves bandwidth and makes it go faster as you don't load all content at once. It loads only when it's selected.