javascript提交表单时验证
太长了,不能发上来,我把它发到贴吧里了,在这里可以看到:http://tieba.baidu.com/f?kz=1076005482...
太长了,不能发上来,我把它发到贴吧里了,在这里可以看到:
http://tieba.baidu.com/f?kz=1076005482 展开
http://tieba.baidu.com/f?kz=1076005482 展开
展开全部
function validate(){
var t1 = document.getElementById('select_cn');
var t2 = document.getElementById('select_wsrs');
var t1val =document.getElementById('gnmj');
var t2val =document.getElementById('syrs');
if(t1.style.display=='block'&&t2.style.display=='block'&&(t1val.value==''||t2val.value=='')){
alert("2个都不能为空");return false;
}else if(t1.style.display=='block'&&t1val.value==''){
alert("第1个不能为空");return false;
}else if(t2.style.display=='block'&&t2val.value==''){
alert("第2个不能为空");return false;
}else{
alert("提交");return true;
}
}
<input type="radio" onclick="showdiv1()" name="aaa"/>选择第1个单选按钮
<input type="radio" onclick="showdiv2()" name="aaa"/>选择第2个单选按钮
<input type="radio" onclick="showdiv12()" name="aaa"/>选择第3个单选按钮
<input id="select_submit" type="submit" value="确定" onclick="return validate();" style="display:none" />
var t1 = document.getElementById('select_cn');
var t2 = document.getElementById('select_wsrs');
var t1val =document.getElementById('gnmj');
var t2val =document.getElementById('syrs');
if(t1.style.display=='block'&&t2.style.display=='block'&&(t1val.value==''||t2val.value=='')){
alert("2个都不能为空");return false;
}else if(t1.style.display=='block'&&t1val.value==''){
alert("第1个不能为空");return false;
}else if(t2.style.display=='block'&&t2val.value==''){
alert("第2个不能为空");return false;
}else{
alert("提交");return true;
}
}
<input type="radio" onclick="showdiv1()" name="aaa"/>选择第1个单选按钮
<input type="radio" onclick="showdiv2()" name="aaa"/>选择第2个单选按钮
<input type="radio" onclick="showdiv12()" name="aaa"/>选择第3个单选按钮
<input id="select_submit" type="submit" value="确定" onclick="return validate();" style="display:none" />
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询