gpt4 book ai didi

html - 在模态框内重定向而不是其他页面

转载 作者:可可西里 更新时间:2023-11-01 13:42:52 25 4
gpt4 key购买 nike

我制作了一个模态框,其中包含用于注册时事通讯的表格。当有人注册时,我希望模式框中的内容更改为感谢消息。

我不太确定这怎么可能?当注册成功时,我已经设置了一个重定向,但那是另一个页面,在我看来这确实会带来糟糕的用户体验。

可以在这里看到一个工作示例:Sign up form

<!DOCTYPE html>
<html lang="en">
<head>
<title>Signuo testpage</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


</head>
<body>

<div class="mk row">
<a href="#">
<div class="col-sm-12 margin_bottom">
<div class="hover11 column">
<figure>
<a href="#" data-toggle="modal" data-target="#nyhedsbrev-tilmelding">
<img src="https://www.votewalton.com/portals/walton/Images/button_newsletter.png" alt="Signuo for our newsletter" class="img-responsive"></img>
</a>
</figure>
</div>
<div class="modal fade" id="nyhedsbrev-tilmelding" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div id="mc_embed_signup">
<form action="https://testing.us16.list-manage.com/subscribe/post?u=c9e771e6f8adb066a0713eb0a&amp;id=6e9f7d0e57" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" >
<div id="mc_embed_signup_scroll">
<h2>Signup for our newsletter</h2>
<p>Every second week we send out a newsletter with tips and trick, good offers for you</p>
<div class="mc-field-group">
<label for="mce-FNAME">Name </label>
<input type="text" value="" name="FNAME" class="" id="mce-FNAME"></input>
</div>
<div class="mc-field-group">
<label for="mce-EMAIL">Emailadress <span class="asterisk">*</span></label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL"></input>
</div>
<div class="mc-field-group input-group" style="display:none;">
<strong>Lande grupper</strong>
<ul>
<li>
<input type="checkbox" value="1" name="group[7][1]" id="mce-group[7]-7-0"></input>
<label for="mce-group[7]-7-0">DK</label>
</li>
</ul>
</div>
<div style="position: absolute; left: -5000px;" aria-hidden="true">
<input type="text" name="b_c9e771e6f8adb066a0713eb0a_6e9f7d0e57" tabindex="-1"></input>
</div>
<div class="clear">
<input type="submit" value="Tilmeld" name="subscribe" id="mc-embedded-subscribe" class="button btn btn-success"></input>
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer" style="text-align: left;">
<span style="font-size: 10px;">
We do not give your information for third part
</span>
</div>
</div>
</div>
</div>
<div class="inner-wrapper bottom-left"></div>
</div>
</a>
</div>
</body>
</html>

最佳答案

您需要使用 ajax 发送请求,从标记中删除操作并使用 jQuery、AngularJS 或类似的 javascript 框架向服务器发送请求。

在成功方法中,您可以隐藏/显示面板以删除控件并显示感谢消息。

<!DOCTYPE html>
<html lang="en">
<head>
<title>Signuo testpage</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


</head>
<body>

<div class="mk row">
<a href="#">
<div class="col-sm-12 margin_bottom">
<div class="hover11 column">
<figure>
<a href="#" data-toggle="modal" data-target="#nyhedsbrev-tilmelding">
<img src="https://www.votewalton.com/portals/walton/Images/button_newsletter.png" alt="Signuo for our newsletter" class="img-responsive"></img>
</a>
</figure>
</div>
<div class="modal fade" id="nyhedsbrev-tilmelding" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div id="mc_embed_signup">
<form class="validate" >
<div id="mc_embed_signup_scroll">
<h2>Signup for our newsletter</h2>
<p>Every second week we send out a newsletter with tips and trick, good offers for you</p>
<div class="mc-field-group">
<label for="mce-FNAME">Name </label>
<input type="text" value="" name="FNAME" class="" id="mce-FNAME"></input>
</div>
<div class="mc-field-group">
<label for="mce-EMAIL">Emailadress <span class="asterisk">*</span></label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL"></input>
</div>
<div class="mc-field-group input-group" style="display:none;">
<strong>Lande grupper</strong>
<ul>
<li>
<input type="checkbox" value="1" name="group[7][1]" id="mce-group[7]-7-0"></input>
<label for="mce-group[7]-7-0">DK</label>
</li>
</ul>
</div>
<div style="position: absolute; left: -5000px;" aria-hidden="true">
<input type="text" name="b_c9e771e6f8adb066a0713eb0a_6e9f7d0e57" tabindex="-1"></input>
</div>
<div class="clear">
<input type="button" value="Tilmeld" name="subscribe" id="mc-embedded-subscribe" class="button btn btn-success"></input>
</div>
</div>
</form>
</div>
<div id="mc_thanks" style="display:none">
<h3 class="text-success">Thanks you </h3>
<button type="button" class="btn btn-success" data-dismiss="modal">Continue to site</button>
</div>
</div>
<div class="modal-footer" style="text-align: left;">
<span style="font-size: 10px;">
We do not give your information for third part
</span>
</div>
</div>
</div>
</div>
<div class="inner-wrapper bottom-left"></div>
</div>
</a>
</div>
</body>

<script>
$(document).ready(function(){
$("#mc-embedded-subscribe").click(function(){

var formData = {
FNAME: $('#mce-FNAME').val(),
EMAIL: $('#mce-EMAIL').val()
}

$.ajax({
type: 'POST',
url: "https://www.votewalton.com",
data: formData,
datatype : "application/json",
success: function(resultData) {
$('#mc_embed_signup').hide();
$('#mc_thanks').show();
},error: function (xhr, status) {
//alert("error")
},complete: function(){
$('#mc_embed_signup').hide();
$('#mc_thanks').show();
}
});
});
});
</script>

</html>

关于html - 在模态框内重定向而不是其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51798260/

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