양식 제출에 대한 유효성 검사를 추가했으나 양식 제출이 중지되었지만 양식 전체가 재설정되기 때문에 문제가 발생했습니다. 친절하게도 return false
의 양식 제출을 중지하고 전체 양식 재설정을 중단 할 수있는 방법을 알려주세요. 감사합니다양식 제출을 중지하고 양식 값을 유지하십시오.
false
을 돌아보다 더 많은 일을 할 필요가
function error()
{
if (!$("#form1 input[name='radio']:checked").val()) {
alert('Error: Please select any check box!');
return false;
}
else {
//alert('One of the radio buttons is checked!');
}
}
<form name="form1" id="form1">
<input name="Name" type="text" id="name" size="70" />
<input name="Age" type="text" id="age" size="70" />
<input type="radio" name="radio" id="A18" value="18" />
<input type="radio" name="radio" id="A19" value="19" />
<input type="submit" onclick="error();" />
</form>
적어도 "버튼"상호 작용에 대해서는 "제출"버튼의 "처리"가 작동 할 수 있지만 이것은 좋은 생각입니다. – Pointy
@Pointy 다른 입력 필드에서 "return"을 누르면 어떻게 될까요? 나는 거의 버튼을 클릭하여에서를 제출하지 않습니다. – meagar
@ meager yes 내 답을 제 편집으로 봅니다 - 당신 말이 맞습니다. – Pointy