如何填写输入,如果如此接近字段集,如何检查输入是否已填写。 [英] How do I check if inputs are filled in, if so close the field set.
本文介绍了如何填写输入,如果如此接近字段集,如何检查输入是否已填写。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Really new to JavaScript and html. I would like to be able to create a function that checks if the input field is filled out and if so it closes down the field set. I have written the closing field-set part I just cant figure out how to validate whether the user has filled out the input fields.
<fieldset>
<legend><a href="#" onclick="doit()">Tell us who you are</a></legend>
<div id="one">
<div>
<label> An injured worker</label>
<input type="radio" name="group1" value="injure"/>
</div>
<div>
<label> An employer </label>
<input type="radio" name="group1" value="employee"/>
</div>
<div>
<label> An injured worker and employer </label>
<input type="radio" name="group1" value="both"/>
</div>
</div>
</fieldset>
我的尝试:
函数doit(){
if(document.getElementById('one')。style.display =='none'){
document.getElementById('one')。style.display ='block';
} else {
document.getElementById('one') .style.display ='none';
}
}
What I have tried:
function doit() {
if(document.getElementById('one').style.display == 'none'){
document.getElementById('one').style.display = 'block';
} else {
document.getElementById('one').style.display = 'none';
}
}
推荐答案
function check(){
var r = document.getElementsByName(group1)
var c = -1
for(var I = 0;我< r.length; i ++){
if(r [i] .checked){
c = i;
}
}
if(c == -1)alert(请选择收音机);
}
function check() {
var r = document.getElementsByName("group1")
var c = -1
for(var i=0; i < r.length; i++){
if(r[i].checked) {
c = i;
}
}
if (c == -1) alert("please select radio");
}
这篇关于如何填写输入,如果如此接近字段集,如何检查输入是否已填写。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文