我有問題在提交時加載jQuery模態窗口。加載一個感謝您彈出表單提交div提交
我想提交一個div加載,以感謝用戶參加比賽。該div打開罰款,如果我添加像這樣的href:<a href="#dialog" name="modal">click here"</a>
但是,我似乎無法使此彈出一次提交。難道我做錯了什麼!?
這是我的形式PHP代碼:
<?php
if($_POST['formSubmit'] == "Submit")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li>You forgot to enter your name</li>";
}
if(empty($_POST['formTown']))
{
$errorMessage .= "<li>You forgot to enter your town</li>";
}
$varName = $_POST['formName'];
$varTown = $_POST['formTown'];
$varAge = $_POST['formAge'];
$varEmail = $_POST['formEmail'];
$varOne = $_POST['hidden-one'];
$varTwo = $_POST['hidden-two'];
$varThree = $_POST['hidden-three'];
$varFour = $_POST['hidden-four'];
$varFive = $_POST['hidden-five'];
if(empty($errorMessage))
{
$fs = fopen("mydata.csv","a");
fwrite($fs,$varName . ", " . $varTown . ", " . $varAge . ", " . $varEmail . ", " . $varOne . $varTwo . $varThree . $varFour . $varFive . "\n");
fclose($fs);
header("Location: #dialog");
exit;
}
}
?>
這是jQuery代碼:
<script>
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function() {
$(this).hide();
$('.window').hide();
});
});
</script>
這是我的html:
<form action="enter.php" method="post" target="_self">
<input class="submit" type="submit" name="formSubmit" value="Submit">
</form>
<div id="boxes">
<div id="dialog" class="window">
<p>Modal content here</p>
</div>
</div>
</div>
</div>
<!-- Mask to cover the whole screen -->
<div id="mask"></div>
</div>
不,不,我明白這一點。我只是覺得一個彈出式的謝謝div是最好的方法。 – kala233