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

js 表单提交前进行确认

WBOY
Release: 2016-06-01 09:54:57
Original
1563 people have browsed it

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>
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template