2015-05-28 23 views
-2

我有一個模板調用game.php把一個div:加載一個PHP模板和使用jquery

<div id="bonus-pub" class="not-display"> 
    <section id="" class="generique"> 
     <div id=""> 
      content 
      <div id="rtr"></div> 
      <div id="gfgf class="not-display"> 
       <h2>gfgf</h2> 
       <p>dsfdsfds</p> 
       <p class="GC_fdfdfd"> 
        <a class="dfdf">Close</a>   </p> 
      </div> 
     </div> 
    </section> 
</div> 

現在我有另一種觀點whitch是作爲動作generique.php後彈出打開:

<section> 
<?php require($file_view);?> 
<script> 
    $(function(){ 
     $('.modal').addClass('generic'); 
    }()) 
</script> 

而另一個文件負責js操作。在這個文件中,我需要創建一個.js調用<div id="bonus-pub" class="not-display">加載到模板generique.php,我想:

<script> 
document.getElementById('bonus-pub').setAttribute('class','display-block'); 
</script> 

但這fonction只把DIV到網頁沒有彈出窗口。所以問題在於,我想在模板game.php之後將<div id="bonus-pub" class="not-display">置於generique.php之後。請幫幫我!! Thx提前!

回答

0

使用ajax可以滿足您的需求。在game.php中將所有div數據存儲在一個php變量中,並將該變量回顯給ajax調用。

game.php 

<?php 
$ret = '<div id="bonus-pub" class="not-display"> 
    <section id="" class="generique"> 
     <div id=""> 
      content 
      <div id="rtr"></div> 
      <div id="gfgf class="not-display"> 
       <h2>gfgf</h2> 
       <p>dsfdsfds</p> 
       <p class="GC_fdfdfd"> 
        <a class="dfdf">Close</a>   </p> 
      </div> 
     </div> 
    </section> 
</div>'; 


echo $ret; 
?> 

你提到的行動後,從AJAX請求的頁面game.php

$.ajax({ 
url:'game.php', 
method:'post', 
success: function(response) 
{ 
    //you have your div data in this response 
} 

fail: function(response) 
{ 
//your ajax request failed 
} 
}); 
+0

Ajax調用是generique.php? – TanGio

+0

是的,阿賈克斯調用是在它 –

+0

但在game.php我有多個div,但我想只通過div> bonus-pub – TanGio

1

編輯:修正了原生JS和jQuery組合。

您是否嘗試過這個,而不是通過使用setAttribute:

<script> 
    document.getElementById('bonus-pub').style.display = "block"; 
</script> 
+0

我得到在控制檯中的錯誤:TypeError:document.getElementById(...)。css不是一個函數 – TanGio

+0

@Gigel我的道歉,我混合JS和jQuery - 嘗試我的修訂 – NightOwlPrgmr

+0

該div>獎金酒吧是從我generique顯示。 PHP :( – TanGio