问题描述
我已经在互联网上搜索了数小时,以试图了解如何在用户提交表单时使可忽略的绿色警报向下滑动(非模式).我认为这与表单验证有关,但不确定.请帮忙.
I've been searching the internet for hours to try to understand how to make a dismissible green alert slide down (non-modal) when a user submits a form. I'm thinking it has something to do with form validation but not sure. Please help.
该代码不起作用,因为当我单击表单上的提交时,什么也没有发生.验证不适用于表格.(表单操作属性为空.)method ="post"
The code isn't working, because when I click submit on the form, nothing happens. The validation is not applying to the form. (the form action attribute has been left empty.) method="post"
我正在使用服务器提供的表单处理脚本(不确定是否会有所不同.)
I am using a form processing script provided by the server (not sure if that makes a difference.)
所以我的问题是:如何链接"提交按钮以将表单发送到服务器,然后通过jQuery显示适合col-md-4的可忽略的成功警报?
so my question is: how can I "link" the submit button to send the form to the sever, then show a dismissible success alert via jQuery that will fit into a col-md-4?
推荐答案
以下是在Bootstrap模态中执行此操作的简化方法.我们在这里所做的就是检查表单是否已通过jQuery提交,然后以模式显示消息.
Here's a simplified way of how you can do it within a Bootstrap modal. All we're doing here is checking if the form has been submitted via jQuery, then showing the message in a modal.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div id="messages" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="messages_content"></div>
</div>
<form id="form" method="post">
<button class="btn btn-default" type="submit">Submit</button>
</form>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$('#form').submit(function(e) {
$('#messages').removeClass('hide').addClass('alert alert-success alert-dismissible').slideDown().show();
$('#messages_content').html('<h4>MESSAGE HERE</h4>');
$('#modal').modal('show');
e.preventDefault();
});
</script>
</body>
</html>
这篇关于通过javascript提交表单时出现Bootstrap成功警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!