2012-09-11 22 views
1

我想在'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 
     } 
     ?> 
+0

你能描述一下你的場景嗎?因爲我們可以提供一個更好的答案,以確定您是否需要使用AJAX或DOM操作等。 –

回答

0

根據PHP文檔,mysql_query()將返回參考結果,而不是結果本身。

你將不得不使用其他方法,如mysql_num_rows()mysql_fetch_assoc()的mysql_query()返回的結果引用。

例如:

$check_crm = mysql_query("select * from crm where party_id='".mysql_real_escape_string($_GET['party_id'])."' limit 1"); 
if (mysql_num_rows($check_crm) > 0) 

BTW:

  • 小心潛在SQL injection。在用戶輸入上至少使用mysql_real_escape_string(),或者更好地將變量綁定到您的查詢。
  • 使用舊的mysql_ *不鼓勵PHP函數。使用PDO庫是首選。檢查Propel或Doctine等ORM。
  • 您可以添加到LIMIT 1您的查詢,以避免無用的處理,如果你的目標是隻有當至少一個匹配CRM給出的發現party_id檢查。
+0

thanx來回答我。現在它會在條件爲真時打開彈出窗口,但當條件爲false時會打開另一個彈出窗口。 –

0

上述代碼將在文檔加載時打開彈出窗口,因爲它包含在$(document).ready函數中。嘗試將其包含在一個函數中,並在條件爲真時調用