繁体   English   中英

为什么Style.Display = None无法使我的按钮不可见?

[英]Why Doesn't Style.Display = None Work To Make My Button Invisible?

我写了一个简单的函数,调用onClick。 当选择一个按钮时,应该基于该特定选择使下一组按钮可见或不可见。 我尝试了多种方法使其工作,但似乎没有一个方法在函数运行后使按钮变得不可见。

这是我到目前为止所拥有的...

function hiddenMess(){

if (document.getElementById('Selection8').checked) {
    document.all('customChoice1').style.visibility = 'hidden';        
    document.getElementById('customChoice1').style.visibility =  'hidden';   
    document.getElementById('customChoice1').style.display = 'none';
}

我使用了所有这三个方法,希望其中一个可以工作,然后我可以消除另外两个。

所谓的按钮是这样的设置

<div class="radio">
  <label><input type="radio" id='Selection8' name="SelectionVal" value="222"  OnClick="hiddenMess()">Test Button 8</label>
</div>
}

这是我要隐藏的按钮。

<input type="radio" id="customChoice1" name="customDChoice"  value="Hello" > Hello"<br>

您的代码成功隐藏了单选按钮本身,而不是标签。 在这里,我们针对包装收音机的标签,而不是:

 function hiddenMess(){ if (document.getElementById('Selection8').checked) { document.getElementById('customChoice1').style.display = 'none'; } } 
 <div class="radio"> <label><input type="radio" id='Selection8' name="SelectionVal" value="222" OnClick="hiddenMess()">Test Button 8</label> </div> <br> <hr> <br> <label id="customChoice1"><input type="radio" name="customDChoice" value="Hello">Hello</label> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM