扩展基于 div 的表中的行

发布于 2024-09-05 21:55:17 字数 324 浏览 3 评论 0原文

我有一堆显示名称的

元素。我想在每个
的侧面添加一个 + 链接,单击该链接会展开
> 并添加更多详细信息(来自 RoR 控制器)。

在网上闲逛后,我找到了 link_to_remote 和相关的 RoR 内容,但我似乎无法找到合适的组合来协同工作。有人可以向我指出教程或展示控制器和视图交互应该是什么样子吗?

谢谢!

I have a stack of <div> elements that show a name. I'd like to include a + link off to the side of each <div> that, when clicked, expands the <div> and adds more detailed information (from a RoR controller).

After poking around on the net, I found link_to_remote and related RoR stuff, but I can't seem to get the right combination to work together. Can someone point me to a tutorial or show what the controller and view interaction should look like?

Thanks!

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

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

发布评论

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

评论(1

摇划花蜜的午后 2024-09-12 21:55:17

您可以使用 Javascript 轻松地完成此操作,如下例所示:

<代码>
<头>
<标题>文本页
<脚本语言=“Javascript”>
  函数toggleDiv(除) {
    if (document.getElementById(divid).style.visibility == '隐藏') {
      document.getElementById(divid).style.visibility = '可见';
    }
    别的 {
      document.getElementById(divid).style.visibility = '隐藏';
    }
  }


<正文>
  +
  
  +
  


如果将 DIV 的初始可见性设置为隐藏,则可以使用上面显示的 toggleDiv 函数来切换给定 ID 的任何 DIV 的可见性。您可能需要调整 DIV 的样式定义以显示在加号旁边(例如,将它们放在表格中相邻的 's 中),但我想我会保持简单。

祝你好运。

You can do this really easily with Javascript in the example below:

<html>
<head>
<title>Text Page</title>
<script language="Javascript">
  function toggleDiv(divid) {
    if (document.getElementById(divid).style.visibility == 'hidden') {
      document.getElementById(divid).style.visibility = 'visible';
    }
    else {
      document.getElementById(divid).style.visibility = 'hidden';
    }
  }
</script>
</head>
<body>
  <span onClick="toggleDiv('div1');" style="cursor:pointer;">+</span>
  <div id="div1" style="visibility:hidden;">This is DIV 1</div>
  <span onClick="toggleDiv('div2');" style="cursor:pointer;">+</span>
  <div id="div2" style="visibility:hidden;">This is DIV 2</div>
</body>
</html>

If you set the initial visibility of the DIV's to hidden, you can use the toggleDiv function shown above to toggle the visibility of any DIV given the ID. You will probably need to tweak the style definitions for the DIVs to display next to the plus signs (put them in adjacent <TD>'s in a table for example), but I figured I'd keep it simple.

Good Luck.

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