我想在'if'條件爲真時打開彈出框 否則它會正常打開。當條件爲真時打開彈出框
但我使用的代碼打開彈出框,無論條件是真還是假。
那麼,幫助我們,並給你的觀點
我使用的腳本。
<script>
$(document).ready(function() {
var id = '#dialog';
//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>
和css在這裏。
<style>
#mask {
position:absolute;
left:0;
top:0;
z-index:9000;
background-color:#000;
display:none;
}
#boxes .window {
position:absolute;
left:0;
top:0;
width:440px;
display:none;
z-index:9999;
padding:20px;
padding-top:0px;
}
#boxes #dialog {
width:975px;
padding-top:0px;
background-color:#ffffff;
background-image: url(../Images/form_bg.png);
background-repeat: no-repeat;
}
</style>
和div的條件。
<?php
$check_crm=mysql_num_rows(mysql_query("select * from crm where party_id='$_GET[party_id]'"));
if($check_crm>0)
{
?>
<div id="boxes">
<div id="dialog" class="window">
<!-- content-->
</div>
</div>
<?php
}
?>
你能描述一下你的場景嗎?因爲我們可以提供一個更好的答案,以確定您是否需要使用AJAX或DOM操作等。 –