gpt4 book ai didi

javascript - 使用 Bootstrap Styling 后提交 POST 表单不再有效

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

上下文:

我正在为我的网站使用 NodeJS、Express、MailTransport 和 Bootstrap,创建一个联系表单来向我发送个人电子邮件。

我创建了一条路由/sayhi 来处理 mailtransport sendMail 方法并在其之后重定向回/

我使用经典的 html 表单:

<form action="/sayhi" method="post" name="sendMail" id="sendMail">

有 3 个输入“来自”、“邮件”和“文本”,与经典的 html 表单和类一起正常工作,如下所示

<form action="/sayhi" method="post" name="sendMail" id="sendMail">
<input type="text" name="from" placeholder="Who?"/>
<input type="email" name="mail" placeholder="Mail?"/>
<input type="text" name="text" placeholder="Why?"/>
<input type="submit" value="Send"/>
</form>

但是当我尝试用 bootstrap 让事情变得更美好时,它不再调用/sayhi

<form action="/sayhi" method="post" name="sendMail" id="sendMail">
<div class="form-group">
<label for="InputName">Name</label>
<input type="text" name="from" id="InputName" aria-describedby="emailHelp" placeholder="John Appleseed" form="sendMail" class="form-control"/>
<small id="nameHelp" class="form-text text-muted">How do you define yourself ?</small>
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" name="mail" id="InputEmail" aria-describedby="emailHelp" placeholder="you@yourdomain.com" form="sendMail" class="form-control"/>
<small id="emailHelp" class="form-text text-muted">To contact you back !</small>
</div>
<div class="form-group">
<label for="Textarea">Something to tell me ?</label>
<textarea name="text" id="Textarea" rows="3" placeholder="blah" form="sendMail" class="form-control"></textarea>
<small id="textHelp" class="form-text text-muted">It can be anything, really!</small>
</div>
<button value="Send" id="submit" type="submit" class="btn btn-primary">Submit</button>
</form>

编辑#1:

为了增加精度,我使用 Pug 作为我的模板引擎,我的表单位于一个特殊的 div 中以将其显示为覆盖层

div.overlay
div#email_form
form(action="/sayhi" method="post" name="sendMail" id="sendMail")
div(class="form-group")
label.lettersB(for="InputName") Name
input(type="text" name="from" class="form-control" id="InputName" aria-describedby="emailHelp" placeholder="John Appleseed" form="sendMail")
small(id="nameHelp" class="form-text text-muted") How do you define yourself ?
div(class="form-group")
label.lettersB(for="InputEmail") Email address
input(type="email" name="mail" class="form-control" id="InputEmail" aria-describedby="emailHelp" placeholder="you@yourdomain.com" form="sendMail")
small(id="emailHelp" class="form-text text-muted") To contact you back !
div(class="form-group")
label.lettersB(for="Textarea") Something to tell me ?
textarea(class="form-control" name="text" id="Textarea" rows="3" placeholder="Don't let The Blank Page Syndrome Hit!" form="sendMail")
small(id="textHelp" class="form-text text-muted") It can be anything, really!
button(value="Send" class="btn btn-primary" id="submit" type="submit") Submit

EDIT#2 问题出在我的覆盖类中,当我将表单从其上取下时,它工作正常,但我不确定是什么导致了这种行为

CSS:

.overlay {
display: none;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background-color:rgba(0, 0, 0, 0.85);
background: url(data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAABl0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuNUmK/OAAAAATSURBVBhXY2RgYNgHxGAAYuwDAA78AjwwRoQYAAAAAElFTkSuQmCC) repeat scroll transparent\9;
z-index:9999;
color: white;
}
.overlay:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}

EDIT#3 问题似乎是我的表单嵌套在另一个 div 中,没有 CSS 的事件,只是它是由按钮触发的事实,但仍然不知道为什么它会这样

最佳答案

您在评论中提供的额外信息表明您正在做的事情:

$(".overlay").click(function(){ 
$(this).fadeOut("fast");
}).children().click(function(e) {
return false;
});

因此,对 .overlay 内的任何元素(包括按钮上的任何元素)的任何点击都不会执行任何操作,因为您拦截了它并返回 false。

关于javascript - 使用 Bootstrap Styling 后提交 POST 表单不再有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41514627/

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