简体   繁体   English

在电台选择上显示/隐藏div

[英]Show/Hide divs on radio selection

I have 3 divs that contain radio with labels and beneath each radio button I would like to show/hide a form based on whether the radio is selected or not. 我有3个div,其中包含带标签的单选按钮,并且在每个单选按钮下方,我希望根据是否选择了单选按钮来显示/隐藏表单。

Code idea: 代码思路:

<div id="radio1"></div>
<div id="form1"></div>

<div id="radio2"></div>
<div id="form2"></div>

<div id="radio3"></div>
<div id="form3"></div>

Using prototype does anyone have any basic idea or suggestion on the best way to accomplish this. 使用原型可以使任何人对实现此目标的最佳方法有任何基本想法或建议。 Any suggested scripts or links would be greatly appreciated. 任何建议的脚本或链接将不胜感激。 I am a newbie to prototype and having a hard time grasping the concept or finding anything helpful online. 我是原型的新手,很难掌握概念或在网上找到任何有用的东西。 In theory I wouldn't think this would be too complicated but thanks in advance for any help. 从理论上讲,我认为这不会太复杂,但是在此先感谢您的帮助。

Use this pattern: 使用以下模式:

<div onclick="$('form1').toggle()" id="radio1"></div>
<div id="form1" style="display"none"></div>

You can chain these together to control other elements as well: 您可以将它们链接在一起以控制其他元素:

<div onclick="$('form1').toggle();$('form2').hide();$('form3').hide()" id="radio1"></div>
<div id="form1" style="display"none"></div>

There are better ways to do this, such as selecting all of the elements that have the same class, hiding them, then showing the clicked element. 有更好的方法来执行此操作,例如选择所有具有相同类的元素,将它们隐藏,然后显示被单击的元素。 But from a beginner's point of view, this should do what you want. 但是从初学者的角度来看,这应该做您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM