这是一个棘手的问题需要解释,但这里有:
我想在bootstrap模式框中显示结果,执行以下操作:
我的问题
一切正常但是母鸡用户点击提交模态框关闭,当我再次打开模态框时,结果在模态框内
如何在用户点击提交时关闭模块框?
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Small Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<script type="text/javascript">
$("form").on("submit", function(e) {
var formData = $(this).serialize();
e.preventDefault();
$.ajax({
url: 'functionTest.php',
data: formData,
type: 'post',
success: function(data) {
$('#resultForm').replaceWith(data);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function()
{
$(".sport").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "get_sport.php",
dataType : 'html',
data: dataString,
cache: false,
success: function(html)
{
$(".tournament").html(html);
}
});
});
$(".tournament").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "get_round.php",
data: dataString,
cache: false,
success: function(html)
{
$(".round").html(html);
}
});
});
});
</script>
</head>
<body>
<center>
<div>
<label>Sport :</label>
<form method="post" id="resultForm" name="resultForm">
<select name="sport" class="sport">
<option selected="selected">--Select Sport--</option>
<?php
include('connect.php');
$sql="SELECT distinct sport_type FROM events";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['sport_type']; ?>"><?php echo $row['sport_type']; ?></option>
<?php
}
?>
</select>
<label>Tournamet :</label> <select name="tournament" class="tournament">
<option selected="selected">--Select Tournament--</option>
</select>
<label>Round :</label> <select name="round" class="round">
<option selected="selected">--Select Round--</option>
</select>
<input type="submit" value="View Picks" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
echo $tour = $_POST['tournament'];
echo $round = $_POST['round'];
}
答案 0 :(得分:2)
您似乎错过了&#34;返回false;&#34;在您的表单提交事件处理程序:
$("form").on("submit", function(e) {
var formData = $(this).serialize();
e.preventDefault();
$.ajax({
url: 'functionTest.php',
data: formData,
type: 'post',
success: function(data) {
$('#resultForm').replaceWith(data);
}
});
//Return false to cancel submit
return false;
});
答案 1 :(得分:1)
我没有测试过您的解决方案,但尝试使用e.stopPropagation();在e.preventDefault();
之前<强>更新强>
为什么你的模态在&lt; head&gt;中部分?
答案 2 :(得分:1)
尝试从按钮
中删除关闭的课程