【发布时间】:2011-11-03 10:56:37
【问题描述】:
【问题讨论】:
-
我们不能用这么少的信息和根本没有代码。请在jsfiddle.net 上发帖好吗?
-
了解JavaScript 和DOM 的基础知识。
-
覆盖函数和答案为javascript hide/show element
标签: javascript html
【问题讨论】:
标签: javascript html
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:
var radioButtonContainer = document.getElementById('radioButtonContainer');
radioButtonContainer.style.display = 'none';
document.getElementById('theButton').onclick = function() {
radioButtonContainer.style.display = 'block';
};
说明:为了方便使用,我将按钮包裹在一个容器内。然后我在 javascript 中选择容器,并将其存储在一个变量中以提高效率和缩短代码。我将显示设置为无(隐藏),然后将事件处理程序附加到 id 为“theButton”(不在 html 中)的元素的单击事件以再次显示。
注意:我用 Javascript 隐藏它们,否则表单可能对不使用 javascript(它们确实存在!)的人无法使用,或者会出现 javascript 错误。
【讨论】:
将单选按钮放在具有样式 display:none 的 div 中,并在提交按钮上 Onclick 事件使用 javascript 调用一个函数,并在该函数中将 display 设置为 div 的块。
【讨论】: