2015-02-06 86 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仍然会正确显示。

注意:这不是好习惯,但它会完成你的老师要求的。