日期:2014-05-16  浏览次数:20318 次

四个文本域不能为空的问题。
在一个表单中,有四个文本域,如果都为空的话不能查询并提示,如果有一个文本域有内容则通过,哪位高手能告诉我怎么做吗?

------解决方案--------------------
<div id= "jia ">
<input type= "text " name= "jia1 " id= "jia1 "> <br>
<input type= "text " name= "jia2 " id= "jia2 "> <br>
<input type= "text " name= "jia3 " id= "jia3 "> <br>
<input type= "text " name= "jia4 " id= "jia4 "> <br>

<input type= "button " value= "check " onclick= "chk(); ">
</div>

<script language= "javascript ">
function chk(){
var txt1 = document.getElementById( "jia1 ").value;
var txt2 = document.getElementById( "jia2 ").value;
var txt3 = document.getElementById( "jia3 ").value;
var txt4 = document.getElementById( "jia4 ").value;

if (!txt1 && !txt2 && !txt3 && !txt4){
alert( "至少填一个 ");
return;
}else{
alert( "ok ");
//提交表单;
}
}
</script>
------解决方案--------------------
如果是form表单提交,用:document.formname.submit();
如果是连接提交:你的函数返回true时候就可以继续走了,如果返回的是false 则连接不起作用
------解决方案--------------------
<script language= "javascript ">
function chk(){
var txt1 = document.getElementById( "brand ").value;
var txt2 = document.getElementById( "schour ").value;

if (!txt1 && !txt2){
alert( "至少填一个 ");
return false;
}else{
alert( "ok ");
//提交表单;
}
}
</script>
<form name= "form1 " method= "post " action= "demand.asp ">
<input name= "brand " type= "text " id= "brand ">
<input name= "schour " type= "text " id= "schour ">
<input type= "submit " name= "Submit " value= "查 询 " onclick= "return chk(); ">
</form>