2015-02-06 89 views
1

我是編碼方面的新手,所以我想從你們那裏得到一些幫助。我必須將每個單個文件(.php)放在一個.html/php文件中。將PHP/Html文件轉換爲html文件

現在,我得到這個代碼:

<html> 
<head> 
    <style type='text/css'> 
     span { 
      text-decoration:underline; 
      color:blue; 
      cursor:pointer; 
     } 
    </style> 
    <script> 
     // show the given page, hide the rest 
     function show(elementID) { 
      // try to find the requested page and alert if it's not found 
      var ele = document.getElementById(elementID); 
      if (!ele) { 
       alert("no such element"); 
       return; 
      } 

      // get all pages, loop through them and hide them 
      var pages = document.getElementsByClassName('page'); 
      for(var i = 0; i < pages.length; i++) { 
       pages[i].style.display = 'none'; 
      } 

      // then show the requested page 
      ele.style.display = 'block'; 
     } 
    </script> 


</head> 
<body> 
    <p> 
    Show page 
     <span onClick="show('Page1');">1</span>, 
     <span onClick="show('Page2');">2</span>, 
     <span onClick="show('Page3');">3</span>. 
    </p> 

<div id="Page1" class="page" style=""> 
    Content of page 1 
</div> 
<div id="Page2" class="page" style="display:none"> 
    Content of page 2 
</div> 
<div id="Page3" class="page" style="display:none"> 
    Content of page 3 
</div> 

</body> 

所以我的問題是;我如何將文件放入'頁面內容1/2/3'?

提前致謝!

+2

這是JavaScript的不是PHP – Rizier123 2015-02-06 21:25:02

+0

你爲什麼這樣做呢? – 2015-02-06 21:25:48

+0

您只需要更多''(「#includedContent」).load(「b.html」);'指向正確的頁面並使用正確的DIV ID加載。 – developerwjk 2015-02-06 21:26:11

回答

1

嘗試include("[path to your file]");include_once("[path to your file]");

http://php.net/manual/en/function.include.php

http://php.net/manual/en/function.include-once.php

+0

我不認爲這回答了這個問題。他要求將所有代碼合併到一個文件中。該解決方案仍然需要多個文件。 – rick6 2015-02-06 21:33:08

+0

@ rick6這是真的,我沒有正確地閱讀這個問題,但希望這個答案會幫助其他人:) – Goudgeld1 2015-02-06 21:47:11

+1

完全。我實際上已經開始爲你寫一個類似的答案,然後我重讀這個問題並改變了我的答案:) – rick6 2015-02-06 21:49:51

1

如果您需要將其他PHP文件與此HTML文件合併,只需將該文件的名稱更改爲.php(如果尚未存在)。然後複製/粘貼你的代碼(爲了處理每個文件)到這個文件的頂部。一定要圍繞你的PHP與<?php?>。如果它在PHP文件中,HTML仍然會正確顯示。

注意:這不是好習慣,但它會完成你的老師要求的。