用button来代替submit提交表单,经过测试完全可行。但下面的代码有一个小失误,在点击button时,会报错,修改一下就可以了。
复制内容到剪贴板
代码:
<?php
$a="Submit, Reset and Button's Method";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$a;?></title>
<script language="javascript">
<!--
//check s is empty or not
function checks(s)
{
var len=s.length;
for(var i=0;i<len;i++)
{
if(s.charAt(i)!="")
{
return false;
}
}
return true;
}
//check text.value is right or not
function textcheck()
{
if(checks(document.whb.username.value))
{
window.alert("Don't let username empty!");
return false;
}
else
{
return true;
}
}
//use button to post form
function postformbybutton()
{
if(checks(document.whb.username.value))
{
window.alert("Don't let username empty!");
}
else
{
document.whb.submit();
//post form information
}
}
//use button to Reset
function resetformbybutton()
{
document.whb.reset();
//reset form information
}
//-->
</script>
</head>
<body >
<div align="center">
<br>
<form name="whb" action="http://127.0.0.1/index.php" method="get">
<table width=400 border=1 cellpadding=0 cellspacing=0 align=center bordercolor=green>
<tr height=50 >
<td colspan=2 align=center ><?=$a;?></td>
</tr>
<tr height=50 >
<td align=right >UserName:   </td>
<td>  <input type="text" name="username" value="Don't Empty UserName! " size=35 onfocus="document.whb.username.select()" >
</td>
</tr>
<tr height=50 >
<td align=right >Password:  </td>
<td>  <input type="password" name="pin" size=36 ></td>
</tr>
<tr height=120 >
<td align=right >Your Sign:   </td>
<td>  
<textarea name="sign" cols=30 rows=6 onfocus="this.select()" > Leave your step at here~~~~</textarea>
</td>
</tr>
<tr height=50 >
<td colspan=2 align=center >
<input type="submit" name="submit" value="submit" onclick="return textcheck()" >      
<input type="reset" name="reset" value="reset">
</td>
</tr>
<tr height=50 >
<td colspan=2 align=center >
<input type="button" name="Sure" value="Sure" onclick="postformbybutton()" >      
<input type="button" name="redo" value="Redo" onclick="resetformbybutton()" >
</td>
</tr>
</table>
</form>
</div>
<div align=center>
<input type="button" name="back" value="BACK" onclick=window.location="index.php">
</div>
</body>
</html>