简体   繁体   English

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

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

I wrote a simple function that calls onClick. 我写了一个简单的函数,调用onClick。 When one button is selected it is supposed to make the next set of buttons visible of invisible based on that particular choice. 当选择一个按钮时,应该基于该特定选择使下一组按钮可见或不可见。 I have tried multiple ways to get it to work and none of them seem to get the button to become invisible after the function runs. 我尝试了多种方法使其工作,但似乎没有一个方法在函数运行后使按钮变得不可见。

Here is what I have so far... 这是我到目前为止所拥有的...

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';
}

I used all 3 of these in the hopes one of them would work, and then I could eliminate the other two. 我使用了所有这三个方法,希望其中一个可以工作,然后我可以消除另外两个。

The button it is called from is setup like this 所谓的按钮是这样的设置

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

This is the button I am trying to make hidden. 这是我要隐藏的按钮。

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

Your code is successfully hiding the radio button itself but not the label. 您的代码成功隐藏了单选按钮本身,而不是标签。 Here we target the label, which wraps the radio, instead: 在这里,我们针对包装收音机的标签,而不是:

 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