0

因此,我试图在 html 中创建一个 javascript 函数,该函数将接受电子邮件地址,然后将它们提交到 Web 表单。我该怎么做呢?这就是我到目前为止所拥有的:

<html>
<form name="form" method="post" action="form-action.php">
<label>
Email:
</label>
<input type="email" name="email"
id="email" size="25" />

<input type="button" value="Submit" onclick="SubmitEmail()" />
</form>
<script type="text/javascript">
    function SubmitEmail() {

                if (!ValidateForm()) {

                    return false;

                }


                document.getElementById("form").submit();
function ValidateForm() {
if (document.getElementById('email').value.length === 0) {

alert("Email is Required");

return false;

}

document.getElementById('EmailRslt').value = document.getElementById('email').value;

return true;

}

</script> 
<td>Your Email is:
</td>
<td id="EmailRslt"></td>
</html>
4

2 回答 2

0

在您的 form-action.php 触发插入查询中,它将在您的数据库表中提交数据。

于 2013-10-18T04:36:58.200 回答
0

if (document.getElementById('email').value.length === 0)将此行替换为

if (document.getElementById('email').value.length == 0)
于 2013-10-18T04:38:37.417 回答