[英]how to hidden a form in javascript
How do I hide a form and display it when a label is clicked?单击 label 时如何隐藏和显示表单?
<form id="form1" action="javascript:return true;" name="form1">
<input type="radio" name="group1" value="opt1" id="opt1"
onclick="show()"><label for="opt1">Option 1</label><br>
<input type="radio" name="group1" value="opt2" id="opt2"
onclick="show()"><label for="opt2">Option 2</label><br>
<input type="radio" name="group1" value="opt3" id="opt3"
onclick="show()"><label for="opt3">Option 3</label><br>
<div id="droplist">
<select name="opt2-select">
<option value='opt2a'>Option 2A</option>
<option value='opt2b'>Option 2B</option>
<option value='opt2c'>Option 2C</option>
</select>
</div>
</form>
<label id="a" onclick="formenable()">click</label>....
function formenable()
{
var o=document.getElementById("form1");
o.style.visibility="hidden"
}
First the form should be hidden default.首先表单应该是默认隐藏的。 When the label is clicked the form should be displayed.
单击 label 时,应显示该表单。 How do I do that?
我怎么做?
<form id="form1" action="javascript:return true;" name="form1" style="display:none">
<script>
function cl(obj) {
div = document.getElementById(obj.id + 'div');
div.style.display = (div.style.display == 'block') ? 'none' : 'block';
}
</script>
<label id="browser" onclick="cl(this)">Browser</label>
<div id="browserdiv" style="display: none">
Browser stuff goes here
<label id="os" onclick="cl(this)">OS</label>
<div id="osdiv" style="display: none">
OS stuff goes here
</div>
</div>
With this, when you click on the Browser label, all of the 'os' still will appear/disappear, without having to do any extra hiding/showing.这样,当您单击浏览器 label 时,所有的“操作系统”仍然会出现/消失,而无需进行任何额外的隐藏/显示。 Probably not exactly what you want, but should get you started.
可能不完全是你想要的,但应该让你开始。
First you have to set CSS style display
of that form to none
.首先,您必须将该表单的 CSS 样式
display
设置为none
。 Then you can use eg.然后你可以使用例如。 jQuery's .show() function .
jQuery 的.show() function 。
CSS styles look like this: CSS styles 看起来像这样:
form#form1 {
display: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.