我似乎无法弄清楚什么是错我的JS。 所有我需要的是功能validateForm
检查表单上的空字段与id
formId
我从来没有得到浏览器的警报。JS功能来验证空输入字段不工作
这里是我的JS:
<script>
$(document).ready(function(){
window.validateForm = validateForm;
function validateForm(formId){
var form=document.getElementById('#formId');
for(i=0; i<form.childNodes.length; i++)
if(form.childNodes[i].tagName!='INPUT'||
typeof form.childNodes[i].value=="undefined")
continue;
else{
var x=form.childNodes[i].value;
if(x==null||x==""){
alert("please fill out all fields");
return false;
}
}
}
</script>
这里是HTML:
<form id="formId" name="myForm" action="mailto:" onsubmit="return validateForm()" method="post">
first field: <input type="text" name="first"></br>
second field: <input type="text" name="second"></br>
third field: <input type="text" name="third"></br>
fourth field: <input type="text" name="fourth"></br>
<input type="submit" value="Submit">
你的意思是什么的不灵? – thefourtheye
我从来没有得到浏览器的警报 – irm