js表单验证,表单不为空验证错误
发布网友
发布时间:2022-05-29 07:17
我来回答
共2个回答
热心网友
时间:2023-10-10 19:39
<!DOCTYPE HTML>
<html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function CheckForm()
{
var reg = /^\s*|\s*$/;
if (document.xpsy.name.value.replace(reg,'').length == 0) {
alert("请输入您姓名!");
return false;
}
}
</script>
</head>
<body>
<form action="/plus/diy.php" enctype="multipart/form-data" method="post" name="xpsy">
<input type="hidden" name="action" value="post" />
<input type="hidden" name="diyid" value="1" />
<input type="hidden" name="do" value="2" />
<table style="width:97%;" cellpadding="0" cellspacing="1">
<tr>
<td align="right" valign="top">姓名:</td>
<td>
<input type='text' name='name' id='name' style='width:250px' class='intxt' value='' />
<input type="hidden" name="dede_fields" value="name,text;tel,text;dtime,select;qq,text;sex,radio;renshu,text;leibie,radio;bz,multitext" />
<input type="hidden" name="dede_fieldshash" value="85b340cb96eea4d8da4347e52200dfb4" />
</td>
</tr>
</table>
<div style="height:30px;padding-top:10px;text-align: center;">
<input type="submit" name="submit" value="提 交" onclick="return CheckForm();"/>
</div>
</form>
</body>
</html>
热心网友
时间:2023-10-10 19:40
看这意思,可以用将onsubmit="CheckForm()" 改成onsubmit="return CheckForm()"
来实现阻止提交。