按钮提交电子邮件,点击调用调用函数,重定向到索引页并显示消息。代码示例:
HTML代码:
JavaScript代码: function submitForm() { // 获取表单信息 var email = document.getElementById("email").value;
// 发送邮件请求 fetch("https://example.com/send_email?email=" + email) .then(response => { // 显示消息 alert("邮件已发送");
// 重定向到索引页
window.location.href = "https://example.com/index";
})
.catch(error => {
console.error(error);
});
}