form提交js判断了input=空提示了 为什么还是提交了
如题提示了:标题不可为空!但是还是提交到?cz=fb这个页面了<scriptLanguage="JavaScript">functioncheckform(){if(do...
如题 提示了:标题不可为空! 但是还是提交到?cz=fb这个页面了
<script Language="JavaScript">
function checkform()
{
if(document.getElementById("yanzi").value=="")
{
alert("标题不可为空!");
document.getElementById("yanzi").value.focus();
return(false);
}
if(document.getElementById("z_gy").value=="")
{
alert("关于类型可为空!");
document.getElementById("z_gy").focus();
return(false);
}
if(document.getElementById("z_nr").value=="")
{
alert("内容不可为空!");
document.getElementById("z_nr").focus();
return(false);
}
return true;
}
</script>
<form name="form1" method="POST" action="?cz=fb" onsubmit="return checkform();">
<table width="600" height="280" border="0">
<tr>
<th height="33" colspan="3" class="lylxsk1" scope="col">发表留言</th>
</tr>
<tr>
<td width="69" height="27" class="lylxsk2">标题:</td>
<td width="500" >
<input type="text" name="thistimemoney" id="yanzi" size="10" class="lylxsk3"></td>
<td width="17"> </td>
</tr>
<tr>
<td height="24" class="lylxsk2" >关于:</td>
<td><select name="z_gy" id="z_gy" class="lylxsk5">
<% %>
</select></td>
<td> </td>
</tr>
<tr>
<td height="152" class="lylxsk2">内容:</td>
<td><textarea name="z_nr" id="z_nr" cols="45" rows="5" class="lylxsk4"></textarea></td>
<td> </td>
</tr>
<tr>
<td colspan="3" align=center>
<input type="submit" value="发表" name="submit" class="anniud">
<input type="reset" class="anniud" value="重置"></td>
</tr>
</table>
</form> 展开
<script Language="JavaScript">
function checkform()
{
if(document.getElementById("yanzi").value=="")
{
alert("标题不可为空!");
document.getElementById("yanzi").value.focus();
return(false);
}
if(document.getElementById("z_gy").value=="")
{
alert("关于类型可为空!");
document.getElementById("z_gy").focus();
return(false);
}
if(document.getElementById("z_nr").value=="")
{
alert("内容不可为空!");
document.getElementById("z_nr").focus();
return(false);
}
return true;
}
</script>
<form name="form1" method="POST" action="?cz=fb" onsubmit="return checkform();">
<table width="600" height="280" border="0">
<tr>
<th height="33" colspan="3" class="lylxsk1" scope="col">发表留言</th>
</tr>
<tr>
<td width="69" height="27" class="lylxsk2">标题:</td>
<td width="500" >
<input type="text" name="thistimemoney" id="yanzi" size="10" class="lylxsk3"></td>
<td width="17"> </td>
</tr>
<tr>
<td height="24" class="lylxsk2" >关于:</td>
<td><select name="z_gy" id="z_gy" class="lylxsk5">
<% %>
</select></td>
<td> </td>
</tr>
<tr>
<td height="152" class="lylxsk2">内容:</td>
<td><textarea name="z_nr" id="z_nr" cols="45" rows="5" class="lylxsk4"></textarea></td>
<td> </td>
</tr>
<tr>
<td colspan="3" align=center>
<input type="submit" value="发表" name="submit" class="anniud">
<input type="reset" class="anniud" value="重置"></td>
</tr>
</table>
</form> 展开
1个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Droid</title>
<script type="text/javascript">
function checkform (form)
{
var reg = /^\s*|\s*$/g;
var yanzi = form.thistimemoney;
var z_gy = form.z_gy;
var z_nr = form.z_nr;
if (yanzi.value.replace(reg,"") == "")
{
alert ("标题不可为空!");
yanzi.focus ();
return false;
}
else if (z_gy.value.replace(reg,"") == "")
{
alert ("关于类型不可为空!");
z_gy.focus ();
return false;
}
else if (z_nr.value.replace(reg,"") == "")
{
alert ("内容不可为空!");
z_nr.focus ();
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name="form1" method="POST" action="?cz=fb" onsubmit="return checkform(this);">
<table width="600" height="280" border="0">
<tr>
<th height="33" colspan="3" class="lylxsk1" scope="col">发表留言</th>
</tr>
<tr>
<td width="69" height="27" class="lylxsk2">标题:</td>
<td width="500"><input type="text" name="thistimemoney" id="yanzi" size="10" class="lylxsk3">
</td>
<td width="17"></td>
</tr>
<tr>
<td height="24" class="lylxsk2">关于:</td>
<td><select name="z_gy" id="z_gy" class="lylxsk5">
<option value="">选择</option>
<option value="111">111</option>
<option value=222>222</option>
</select></td>
<td></td>
</tr>
<tr>
<td height="152" class="lylxsk2">内容:</td>
<td><textarea name="z_nr" id="z_nr" cols="45" rows="5" class="lylxsk4"></textarea>
</td>
<td></td>
</tr>
<tr>
<td colspan="3" align=center><input type="submit" value="发表" name="submit" class="anniud"> <input type="reset" class="anniud"
value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询