[英]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.