可以再次更改RadioButtons再次显示
我有一个带有3个radionbutton的容器,其中2个放射线室旁边有另一个radiobuttons,但它们的显示却没有。当我单击RadioButton时,我想显示隐藏的radiobuttons,当我单击另一个RadionButton时,我希望它再次显示为无。
`function showHiddenText()
{
if (document.getElementById("diger").checked) {
const hiddenInput = document.getElementById("hidden-input");
hiddenInput.style.display = "block";
} else if (document.getElementById("diger").checked == false) {
hiddenInput.style.display = "none";
}
}`
我写的是一个简单的功能,但是如果部分不起作用。当我显示隐藏的无线电按钮时,它们不会再消失了。 radionbuttons hiddenpart
i got a container with 3 radionbuttons and 2 of the radiobuttons have another radiobuttons next to them but their displays are none . When i click the radiobutton i wanna display the hidden radiobuttons and when i click another radionbutton i want it's display to be none again .
`function showHiddenText()
{
if (document.getElementById("diger").checked) {
const hiddenInput = document.getElementById("hidden-input");
hiddenInput.style.display = "block";
} else if (document.getElementById("diger").checked == false) {
hiddenInput.style.display = "none";
}
}`
It's a simple function i write to do that but else if part is not working . When i display hidden radio buttons they dont disappear ever again.
radionbuttons
hiddenpart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
const
变量是块范围的。因此,在中,如果
语句hidendInput
是未定义的。顺便说一下
,您可以通过语句用
else
替换else来使其更简单,
或者更多:或更多:
const
variables are block scoped. So, in theelse if
statementhiddenInput
is undefined.Move it above the statements
By the way, you can make it simpler by replacing the
else if
statement withelse
:Or even more:
确保您的收音机按钮具有相同的名称。
比较具有相同名称的无线电按钮。
然后将OnClick =“ ShowHidDentext()”添加到输入,然后:
html:
js::
Make sure your radio buttons have the same name.
Radio buttons with same name are compared to each other.
Add onclick="showHiddenText()" to inputs, then:
html:
js: