如何在JavaScript中单击按钮时隐藏单选按钮
可能重复: 如何隐藏单选按钮,单选按钮应仅在用户单击“显示”按钮时显示 plz你能给出这个示例程序或建议站点吗如何在JavaScript中单击按钮时隐藏单选按钮,javascript,html,Javascript,Html,可能重复: 如何隐藏单选按钮,单选按钮应仅在用户单击“显示”按钮时显示 plz你能给出这个示例程序或建议站点吗 提前感谢您将单选按钮放在一个带有样式显示的div中:none和on submit buttons Onclick event,使用javascript调用函数,并在该函数中为div设置display as block。html: <div id="radioButtonContainer"> <input type="radio" name="selecto
提前感谢您将单选按钮放在一个带有样式显示的div中:none和on submit buttons Onclick event,使用javascript调用函数,并在该函数中为div设置display as block。html:
<div id="radioButtonContainer">
<input type="radio" name="selector" value="option1" id="selector1" /><label for="selector1">Option 1</label><br />
<input type="radio" name="selector" value="option2" id="selector2" /><label for="selector2">Option 2</label><br />
<input type="radio" name="selector" value="option3" id="selector3" /><label for="selector3">Option 3</label><br />
</div>
说明:为了便于使用,我将按钮包装在一个容器中。然后,我选择javascript中的容器,并将其存储在一个变量中,以提高效率并缩短代码。我将display设置为none隐藏它,然后将事件处理程序附加到id为theButton not in html的元素的click事件以再次显示它
注意:我用Javascript隐藏它们,因为如果不使用Javascript,表单可能无法使用,因为它们确实存在!,或者当出现javascript错误时。我们不能用这么少的信息和完全没有代码。你能在上面发些东西吗?学习和的基本知识。包括函数和答案
var radioButtonContainer = document.getElementById('radioButtonContainer');
radioButtonContainer.style.display = 'none';
document.getElementById('theButton').onclick = function() {
radioButtonContainer.style.display = 'block';
};