隐藏ASP单选按钮文字 [英] Hide asp radio button text

查看:57
本文介绍了隐藏ASP单选按钮文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP单选按钮,我想在javascript中将其可见性设置为false.

I have a asp radio button and i want to set it's visibility to false in javascript.

<asp:RadioButton  ID="rad1" Text="my radio button" runat="server" GroupName="b" />

我正在尝试使用javascript中的以下代码.

I am trying below code in javascript .

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

但是它仅禁用单选按钮,但文本我的单选按钮"可见.我尝试将text,value属性设置为空白文本,但是没有用.那么我该如何隐藏该单选按钮的文本.

But it disables only radio button but the text "my radio button" is visible. I tried setting text , value property to blank text but it didn't work. So how can i hide the text of that radio button.

推荐答案

原因是:

<asp:RadioButton  ID="rad1" Text="my radio button" runat="server" GroupName="b" /> 

实际上是渲染到的(您可以查看源代码):

Is actually rendered to (you can view the source):

<input name="b" id="rad1" type="radio" value="rad1">
<label for="rad1">my radio button</label>

因此,如果要同时隐藏两者,则必须执行以下操作:

So if you want to make both hidden you have to do something like:

var rad1 = document.getElementById("rad1");
rad1.style.visibility = "hidden";
rad1.nextSibling.style.visibility = "hidden";

或更简单的方法是将单选按钮放在 div 中,例如:

or an easier approach would be to place the radio button in a div for example, something like:

<div id="foo">
    <asp:RadioButton  ID="rad1" Text="my radio button" runat="server" GroupName="b" />
</div>

然后执行:

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

这篇关于隐藏ASP单选按钮文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆