我需要一些简单的快速帮助,
这是我要编辑的表单:
<div class="form_radio">
<div class="form-group">
<label>Gender</label>
<br />
<form name="gender-male-female">
<input type="radio" name="gender" value="m" id="m">Male
<input type="radio" name="gender" value="f" id="f">Female
</div>
</div>
这是一个有效的例子:
<div class="form_password">
<div class="form-group">
<label>Create a password</label>
<label class="sr-only" for="Password">Create a password</label>
<input type="password" class="form-control" id="password" onfocus="emptyElement('status')" maxlength="16">
</div>
</div>
我想说:
id =“gender”onfocus =“emptyElement('status')”
进入广播组,但我不知道如何
答案 0 :(得分:0)
请尝试使用此代码并告诉我们。希望它对你有所帮助。
<form name="myForm">
<input type="radio" name="gender" value="m" id="m" /> Male
<input type="radio" name="gender" value="f" id="f"/> Female
</form>
<script>
var rad = document.myForm.myRadios;
var prev = null;
for(var i = 0; i < rad.length; i++) {
rad[i].onclick = function() {
(prev)? console.log(prev.value):null;
if(this !== prev) {
prev = this;
}
console.log(this.value)
};
}
</script>
或强>
对于客户端验证,这里有一些Javascript来检查选择了哪一个:
if(document.getElementById('m').checked) {
//Male radio button is checked
}else if(document.getElementById('f').checked) {
//Female radio button is checked
}