在 php 条件下显示弹出框
Show popup box in if conditions in php
我试图在 if 条件下显示一个弹出框。
这是我的 HTML :
<div id="my-confirm-dialog" class="dialog-overlay">
<div class="dialog-card">
<div class="dialog-question-sign"><i class="fa fa-question"></i></div>
<div class="dialog-info">
<h5>Thank You !</h5>
<p>Your Messag has been sent.</p>
<button class="dialog-confirm-button">OK</button>
</div>
</div>
</div>
这是我的脚本:
<script>
$(document).ready(function() {
function showDialog(id){
var dialog = $('#' + id),
card = dialog.find('.dialog-card');
dialog.fadeIn();
card.css({
'margin-top' : -card.outerHeight()/2
});
}
function hideAllDialogs(){
$('.dialog-overlay').fadeOut();
}
$('.dialog-confirm-button, .dialog-reject-button').on('click', function () {
hideAllDialogs();
});
$('.dialog-overlay').on('click', function (e) {
if(e.target == this){
hideAllDialogs();
}
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
hideAllDialogs();
}
});
$('.dialog-show-button').on('click', function () {
var toShow = $(this).data('show-dialog');
showDialog(toShow);
});
});
</script>
这是我的按钮:
<span class="dialog-show-button" data-show-dialog="my-confirm-dialog">Dialog Button</span>
每当我点击按钮时,就会出现一个弹出框。到现在一切都很好。现在我要做的是,当我发送邮件并且条件为真时,将出现此弹出框。
这是条件,在此警告框中工作正常。
if ($mail == true){
echo '<script type="text/javascript">alert("Thankyou for Contacting Shagun Sweets")</script>';
}
我只是想在警告框的位置显示弹出框,我已经尝试过类似的方法但没有帮助。
<?php
if ($mail == true){
echo "<script>";
echo "showDialog('my-confirm-dialog');";
echo "</script>";
}
?>
请帮帮我。
在 DOM 就绪函数之外定义 showDialog
函数。
并且,改为这样做:
$script = '<script type="text/javascript">';
$script .= 'showDialog('my-confirm-dialog');';
$script .= '</script>';
echo $script;
如果您的提醒有效,那么这也应该有效
您的 php 脚本应该有效。但它可能不起作用,因为您实际上是在页面加载之前检查邮件是否为真。这是我建议您做的,将 php 函数编辑为:
<?php if($mail == true){
echo "<script>var show_dialog = true;</script>";
} ?>
在您的脚本中:
$(document).ready(function() {
// put me in the end
if(show_dialog != undefined && show_dialog){
showDialog('my-confirm-dialog');
}
});
我试图在 if 条件下显示一个弹出框。 这是我的 HTML :
<div id="my-confirm-dialog" class="dialog-overlay">
<div class="dialog-card">
<div class="dialog-question-sign"><i class="fa fa-question"></i></div>
<div class="dialog-info">
<h5>Thank You !</h5>
<p>Your Messag has been sent.</p>
<button class="dialog-confirm-button">OK</button>
</div>
</div>
</div>
这是我的脚本:
<script>
$(document).ready(function() {
function showDialog(id){
var dialog = $('#' + id),
card = dialog.find('.dialog-card');
dialog.fadeIn();
card.css({
'margin-top' : -card.outerHeight()/2
});
}
function hideAllDialogs(){
$('.dialog-overlay').fadeOut();
}
$('.dialog-confirm-button, .dialog-reject-button').on('click', function () {
hideAllDialogs();
});
$('.dialog-overlay').on('click', function (e) {
if(e.target == this){
hideAllDialogs();
}
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
hideAllDialogs();
}
});
$('.dialog-show-button').on('click', function () {
var toShow = $(this).data('show-dialog');
showDialog(toShow);
});
});
</script>
这是我的按钮:
<span class="dialog-show-button" data-show-dialog="my-confirm-dialog">Dialog Button</span>
每当我点击按钮时,就会出现一个弹出框。到现在一切都很好。现在我要做的是,当我发送邮件并且条件为真时,将出现此弹出框。 这是条件,在此警告框中工作正常。
if ($mail == true){
echo '<script type="text/javascript">alert("Thankyou for Contacting Shagun Sweets")</script>';
}
我只是想在警告框的位置显示弹出框,我已经尝试过类似的方法但没有帮助。
<?php
if ($mail == true){
echo "<script>";
echo "showDialog('my-confirm-dialog');";
echo "</script>";
}
?>
请帮帮我。
在 DOM 就绪函数之外定义 showDialog
函数。
并且,改为这样做:
$script = '<script type="text/javascript">';
$script .= 'showDialog('my-confirm-dialog');';
$script .= '</script>';
echo $script;
如果您的提醒有效,那么这也应该有效
您的 php 脚本应该有效。但它可能不起作用,因为您实际上是在页面加载之前检查邮件是否为真。这是我建议您做的,将 php 函数编辑为:
<?php if($mail == true){
echo "<script>var show_dialog = true;</script>";
} ?>
在您的脚本中:
$(document).ready(function() {
// put me in the end
if(show_dialog != undefined && show_dialog){
showDialog('my-confirm-dialog');
}
});