Javascript 如何动态隐藏文本字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6013499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:52:59  来源:igfitidea点击:

How to hide a text field dynamically

javascripthtml

提问by Raghu

I am having 3 radio buttons r1, r2 and r3 and 4 text fields and text boxes..

我有 3 个单选按钮 r1、r2 和 r3 以及 4 个文本字段和文本框。

If i am clicking r1, all the text field and text boxes should be hided. but if i am clicking r2 and r3 the text field and text box should be displayed..

如果我单击 r1,则应隐藏所有文本字段和文本框。但如果我点击 r2 和 r3 文本字段和文本框应该显示..

回答by Harry Joy

use css property to achieve this. Use displayor visibility.

使用 css 属性来实现这一点。使用displayvisibility

Whenever r1 is active use as following:

每当 r1 处于活动状态时,请按如下方式使用:

document.getElementById("idOfTextField").style.display = "none";

or

或者

document.getElementById("idOfTextField").style.visibility = "hidden";

And when r2 or r3 is active do as follow:

当 r2 或 r3 处于活动状态时,请执行以下操作:

document.getElementById("idOfTextField").style.display = "block";

or

或者

document.getElementById("idOfTextField").style.visibility = "visible";

You have to do this for all textboxes.

您必须对所有文本框执行此操作。

Note:- this is done using javaScript not jQuery.

注意:- 这是使用 javaScript 而不是 jQuery 完成的。