button和sumbit提交表单的区别

﹥>﹥吖頭↗ 提交于 2020-01-14 12:15:24

      最新弄了个asp的软件,提交表单有点生疏了,下面总结了一下通过button和sumbit两种方式来提交表单:

      sumbit提交表单 

View Code
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function checkForm()
{
  
if(document.form1.userName.value.length==0)
  {
     alert(
"请输入用户名!");
     
return false;
  }
  
return true
  document.form1.submit(); 
}
</script>
</head>

<body>
<form name="form1"  method="post" action="ygdacx.html" onsubmit="return checkForm()">
  
<input type="text" name="userName" size="10" />
   
<input type="submit" value="提 交" />
</form>
</body>
</html>

 

 button提交表单 

View Code
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function checkForm()
{
  
if(document.form1.userName.value.length==0)
  {
     alert(
"请输入用户名!");
     
return false;
  }
  document.form1.action 
="ygdacx.html";   
  document.form1.submit(); 
}
</script>
</head>

<body>
<form name="form1"  method="post">
  
<input type="text" name="userName" size="10" />
   
<!--<input type="submit" value="提 交" />  -->
   
<input type="button" value="提 交"  onclick="checkForm()" />
</form>
</body>

大家看出区别了吗,不说了..呵呵

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!