2016-07-27 26 views
-3

Showmodaltext可以是「home.php」。如果showmodaltext是「home.php」,它應該指定某些CSS值。但如果它是別的東西,例如「contact.php」,它應該分配不同的CSS值。 但是,當我運行此代碼showmodaltext不會給予if語句中的任何值。即使它可以加載頁面。所以在if語句之前,showmodaltext是「home.php」,但在if語句中,它突然變空了。所以showmodaltext是if語句中的一個空變量。負載()內的If/else函數

#mysite-main-page和.mysite-main-page是我用來顯示home.php頁面的兩個div。

這裏是我的代碼:

$("#mysite-main-page").load(showmodaltext , function(){ 
     if (showmodaltext.substring(0, 4) == "home"){ 
      $(".mysite-main-page").css('background-color','transparent'); 
      $(".mysite-main-page").css('text-align','center'); 
      //alert("You pressed home->" + showmodaltext + "<-"); //testing if it works 
     } else { 
      $(".mysite-main-page").css('background-color','rgba(255,255,255,0.6)'); 
      $(".mysite-main-page").css('text-align','left');  
      //alert("You did not press home->" + showmodaltext + "<-"); //testing if it works 
     } 

我想加載一個頁面,而是取決於它是否是「home.php」與否,它應該分配不同的CSS值。但這不起作用。有沒有辦法做到這一點?

+3

定義「不工作」 – Utkanos

+1

請閱讀[問],尤其是如何創建[mcve] –

+1

您已經在使用它了,但我們不知道wha如果它符合條件,並且我們不知道'#mysite-main-page'或'.mysite-main-page'是*(這是兩個不同的選擇器?)* – adeneo

回答

0

發現了問題:

$("#mysite-main-page").load(showmodaltext , {showmodaltext, function(){ 
     if (showmodaltext.substring(0, 4) == "home"){ 
      $(".mysite-main-page").css('background-color','transparent'); 
      $(".mysite-main-page").css('text-align','center'); 
      //alert("You pressed home->" + showmodaltext + "<-"); //testing if it works 
     } else { 
      $(".mysite-main-page").css('background-color','rgba(255,255,255,0.6)'); 
      $(".mysite-main-page").css('text-align','left');  
      //alert("You did not press home->" + showmodaltext + "<-"); //testing if it works 
     }} 

$( 「#mysite的-主頁」)負載(showmodaltext,{showmodaltext,()的函數

當時的重要組成部分。我不得不發送變量到服務器