如何显示/隐藏一个当单击单选按钮时,当所有具有相同的类时?
具有相同的类时?
我有这个 JavaScript 代码:
$("#midden-offertes form .subvragen").hide();
$("#midden-offertes form .veld .radio :radio").change(function()
{
if (this.value === 'Ja')
{
$("#midden-offertes form .subvragen",this).show()
}
else
{
$("#midden-offertes form .subvragen",this).hide();
}
});
我还有一个带有不同单选按钮的
但每个 .radio
按钮都有自己的 .subvragen
。如何更改此 JavaScript 代码,以便当我单击每个单选按钮时仅显示每个单选按钮中的 .subvragen
?现在,当我单击单选按钮时,将显示所有 .subvragen
。编辑:
我已经上传了文件。您可以在这里看到它们:http://mikevierwind.nl/karel/offerterelatie.html
I have this JavaScript code:
$("#midden-offertes form .subvragen").hide();
$("#midden-offertes form .veld .radio :radio").change(function()
{
if (this.value === 'Ja')
{
$("#midden-offertes form .subvragen",this).show()
}
else
{
$("#midden-offertes form .subvragen",this).hide();
}
});
I also have a <form>
with different radio buttons. When I click on a radio button, the .subvragen
<div>
must be shown.
But every .radio
button has its own .subvragen
<div>
. How can I change this JavaScript code so that only the .subvragen
within each radio button is shown when I click on that radio button?
When I click on a radio button now, all the .subvragen
<div>
s are shown.
Edit:
I have uploaded the files. You can see them here: http://mikevierwind.nl/karel/offerterelatie.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您获得的 HTML,您可以使用以下 JavaScript(我认为)
: ,如果您可以将
id
属性添加到您的subvragen
和收音机中,您就可以使用它们 - 它会使 JavaScript更少依赖 HTML 嵌套。
例如,如果你的 HTML 是这样的:
那么你的 JavaScript 就会像这样:
Looking at the HTML you’ve got, you could use the following JavaScript (I think):
Alternatively, if you could add
id
attributes to yoursubvragen
<div>
s and radios, you could use them — it’d make the JavaScript less reliant on the HTML nesting.E.g. if your HTML were like this:
Then your JavaScript would go something like this: