Home  >  Article  >  Web Front-end  >  js 表单提交前进行确认

js 表单提交前进行确认

WBOY
WBOYOriginal
2016-06-01 09:54:571489browse

js提交表单,我们可以使用document.getElementById("formid").submit()来实现。

提示框可以使用window.confirm来实现。

下面来看一下具体的代码:

<code>

<title>js表单提交前进行确认提示</title>
<script type="text/javascript">
function formSubmit()
{
     if (window.confirm("确定提交表单吗?")){
            document.getElementById("form1").submit();
     }
} 
</script>


<form id="form1" method="post" action="/abc.php">
First name: 
<input type="text" name="FirstName" value="wu" size="20">
<br>Last name: 
<input type="text" name="LastName" value="xiao" size="20">
<br>
<input type="button" value="使用js提示是否提交表单" onclick="formSubmit();">
</form> 

</code>

你可以复制本文章的代码到这里运行一把,马上去运行

小结:实现js 表单提交主要使用到js的submit()方法。实现提示是否提交表单主要使用到window.confirm()方法。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn