一、表单submit提交
<form action="" method="post" name="addForm" onsubmit="return CheckPost();"><!--提交前先验证表单-->
<div>用户:<input type="text" size="10" name="user" maxlength="20"/></div>
<div>标题:<input type="text" name="title" maxlength="50"/></div>
<div>内容:<textarea name="content" rows="8" cols="30"></textarea></div>
<div>
<input type="submit" name="submit" value="发表留言"/>
</div>
</form>
<script language="javascript">
function CheckPost ()
{
if (addForm.user.value == "")
{
alert("请填写用户名!");
addForm.username.focus();
return false;
}
if (addForm.title.value.length ===0)
{
alert("标题不能为空!");
addForm.title.focus();
return false;
}
return true;
}
</script>
二、button提交
<script language="javascript">
function SendForm ()
{
if(CheckPost())
{
document.addForm.submit();
//$("#formid").submit();
}
}//提交前先验证表单
function CheckPost ()
{
if (addForm.user.value == "")
{
alert("请填写用户名!");
addForm.username.focus();
return false;
}
if (addForm.title.value.length ===0)
{
alert("标题不能为空!");
addForm.title.focus();
return false;
}
return true;
}
</script>
<form action="" method="post" name="addForm" id="formid">
<div>用户:<input type="text" size="10" name="user" maxlength="20"/></div>
<div>标题:<input type="text" name="title" maxlength="50"/></div>
<div>内容:<textarea name="content" rows="8" cols="30"></textarea></div>
<div><input type="button" name="submit" value="发表留言" onclick="SendForm();"/></div>
</form>
三、ajax提交,