Java 使用单选按钮并将其隐藏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16515577/
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-16 07:13:48  来源:igfitidea点击:

Use a radio button and make it hidden as well

javahtmlformsjsp

提问by Nachiket Kamat

Is there any way to use a radio button and make it hidden as well?

有没有办法使用单选按钮并将其隐藏?

I am trying to store a value inside 4 automatically (JSP) generated radio buttons. I need to place one more radio button which will hold some default value but it should be hidden from user. Is there any way for this?

我试图在 4 个自动(JSP)生成的单选按钮中存储一个值。我需要再放置一个单选按钮来保存一些默认值,但它应该对用户隐藏。有什么办法吗?

回答by Andrew Thompson

See HTML Forms: Control Typesfor:

请参阅HTML 表单:控件类型

hidden controlsAuthors may create controls that are not rendered but whose values are submitted with a form. Authors generally use this control type to store information between client/server exchanges that would otherwise be lost due to the stateless nature of HTTP (see [RFC2616]). The INPUTelement is used to create a hidden control.

隐藏控件作者可以创建不呈现但其值随表单提交的控件。作者通常使用这种控制类型来存储客户端/服务器交换之间的信息,否则这些信息会因 HTTP 的无状态性质而丢失(参见 [RFC2616])。该INPUT元素用于创建隐藏控件。

回答by JDGuide

I suggested to use HIDDEN FIELD for your purpose.But still,you have some other purpose for using radio button then,make your radio button hidden, by using style sheet as follow:-

我建议使用 HIDDEN FIELD 来满足您的目的。但是,您还有其他一些使用单选按钮的目的,然后使用样式表隐藏您的单选按钮,如下所示:-

<input type="radio" name="radiobt" value="4" style="display:none"/>

Hope it will help you.

希望它会帮助你。

回答by vijayr

I there any reason to hidden radio button?. While loading form or page you can hide the radio button by using jQuery hide option. whenever you need you can show to the page. Otherwise you can use css - display:none option to hide a radio button from the page. Hope this will helps you.

我有什么理由隐藏单选按钮吗?在加载表单或页面时,您可以使用 jQuery 隐藏选项隐藏单选按钮。只要你需要,你可以显示到页面。否则,您可以使用 css - display:none 选项隐藏页面中的单选按钮。希望这会帮助你。

回答by DenyaK

You can hide a radio button by using the set.Visible(Boolean flag) method from javax.swing:

您可以使用 javax.swing 中的 set.Visible(Boolean flag) 方法隐藏单选按钮:

myButton.setVisible (false);

myButton.setVisible (false);

回答by MarkPlewis

You should avoid using display:noneor visibility:hiddenon form field elements because this will have a negative impact on accessibility. Users who are navigating your website via the keyboard (no mouse) will not be able to tab between form elements and check/uncheck them. You could try using the following instead:

您应该避免在表单字段元素上使用display:nonevisibility:hidden,因为这会对可访问性产生负面影响。通过键盘(无鼠标)浏览您的网站的用户将无法在表单元素之间切换以及选中/取消选中它们。您可以尝试使用以下方法:

-moz-appearance: none;
-webkit-appearance: none;
appearance: none;

Update:Due to a known bug in Firefox, the radio button's border and dot are still visible when appearance: nonehas been applied. Setting the opacity to zero instead seems to be working for me:

更新:由于Firefox 中的一个已知错误,应用后单选按钮的边框和点仍然可见appearance: none。将不透明度设置为零似乎对我有用:

opacity: 0;