"> -6ren">
gpt4 book ai didi

javascript - html表单提交原因 "Form submission canceled because the form is not connected"

转载 作者:行者123 更新时间:2023-12-03 03:04:51 25 4
gpt4 key购买 nike

我显示了以下 HTML 表单,我想在用户单击“发送”按钮时调用 javascript 函数 sendMail():

<script type="text/template" id="compose-view-template">
<form id="email-compose" class="form-email-compose" method="get" action="javascript:sendMail();">
<div class="form-group">
<input type="email" id="input-to" placeholder="To" class="input-transparent form-control"
value="<%= receiver %>">
</div>
<div class="form-group">
<input type="text" id="input-subject" placeholder="Subject" class="input-transparent form-control"
value="<%= subject %>">
</div>
<div class="form-group">
<textarea rows="10" class="form-control" id="wysiwyg" placeholder="Message"><%- body %></textarea>
</div>
<div class="clearfix">
<div class="btn-toolbar pull-xs-right">
<button type="reset" id="compose-discard-button" class="btn btn-gray">Cancel</button>
<button type="submit" id="compose-send-button" onclick="" class="btn btn-danger">&nbsp;&nbsp;&nbsp;Send&nbsp;&nbsp;&nbsp;</button>
</div>
</div>
</form>

和 Javascript 函数:

function sendMail(){

console.log("submit new email");

}
</script>

但是当我点击“发送”时,出现以下错误

Form submission canceled because the form is not connected

即使我提到了对表单或按钮 onclick 的操作,我仍然遇到相同的错误。有人知道我该如何解决这个问题吗?

最佳答案

这是一个 html 页面的示例,上面有一个按钮,当你点击它时,会出现一个 javascrippt 函数,并在你的页面上为你写一条消息。

注意:

要发送真实的电子邮件,您必须为其创建后端代码。

                <script>
function sendRequest(){
console.log( "complete the function");
document.getElementById("data").innerHTML = "Email is sent!";

}

</script>
    <!DOCTYPE html>
<html>
<body>

<button type="button" onClick="sendRequest()" >Click me </button>

<p id="data"> <p>

</body>
</html

关于javascript - html表单提交原因 "Form submission canceled because the form is not connected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47217042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com