码迷,mamicode.com
首页 > 其他好文 > 详细

submit和button提交表单的区别

时间:2016-05-13 08:58:24      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>submit</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>

当类型为submit的input提交form表单时,配合onsubmit写事件。

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>button</title>
<script type="text/javascript">
function checkForm(){
    if(document.form1.userName.value.length==0){
        alert("请输入用户名!");
        return false;
    }
    document.form1.action="/email.php"
    document.form1.submit();
}
</script>
</head>
<body>
<form name="form1" method="post">
<button type="button" value="提 交"  onclick="checkForm()"></button>
</form>
</body>

使用button的话是先走一个onclick事件,在事件末端指向要跳转的php页面即可。

 

submit和button提交表单的区别

标签:

原文地址:http://www.cnblogs.com/wangjiayi/p/5485458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!