急求一个js判断函数
<script language="javascript" type="text/javascript">function checkForm(o) {
var con = "";
for(var i=0;i<o.con1.length;i++){
if (o.con1[i].checked) {
con+=o.con1[i].value + ",";
}
}
if(con!=""){
//alert(con);
if(o.con2[o.con2.length-1].checked && o.con21.value==""){
alert("题二你选择了最后一个选项,请在文本框内输入内容!");
return false;
}
//alert(o.con21.value);
return true;
}else{
alert("题一至少选择一项!");
return false;
}
}
</script>
<form name="form1" action="#" onsubmit="return checkForm(this);">
题一:<input type="checkbox" name="con1" value="1" />选项1 <input type="checkbox" name="con1" value="2" />选项2<br />
<script language="javascript" type="text/javascript">
function checkForm(o) {
var con = "";
for(var i=0;i<o.con1.length;i++){
if (o.con1[i].checked) {
con+=o.con1[i].value + ",";
}
}
if(con!=""){
//alert(con);
if(o.con2[o.con2.length-1].checked && o.con21.value==""){
alert("题二你选择了最后一个选项,请在文本框内输入内容!");
return false;
}
//alert(o.con21.value);
return true;
}else{
alert("题一至少选择一项!");
return false;
}
}
</script>
<form name="form1" action="#" onsubmit="return checkForm(this);">
题一:<input type="checkbox" name="con1" value="1" />选项1 <input type="checkbox" name="con1" value="2" />选项2<br />
题二:<input type="radio" name="con2" value="1" />选项1 <input type="radio" name="con2" value="2" />选项2<br />
题三:<input name="Email" type="text" maxlength="129" style="height:20;width:200;" /><br>
<input type="submit" name="submit" value="提交" />
</form>
想把检验是否输入邮件的判断代码加到里面,判断邮件的代码如下:
<script language="javascript" type="text/javascript">
function checkForm(o) {
if (Email.value == "" || String( objForm.Email.value ).indexOf("@") == -1 || String( objForm.Email.value).indexOf
(".") == -1 ) {
alert( 'Please enter a valid email address.' );
return false;
}
return true;
}
</script>