将PHP/Html文件转换为Html文件
我在编码等方面是个新手,所以我想从你们这里得到一些帮助。我必须将每个文件(.php)放在一个.html/php文件中 现在我得到了这个代码:将PHP/Html文件转换为Html文件,php,html,file,Php,Html,File,我在编码等方面是个新手,所以我想从你们这里得到一些帮助。我必须将每个文件(.php)放在一个.html/php文件中 现在我得到了这个代码: <html> <head> <style type='text/css'> span { text-decoration:underline; color:blue; cursor:pointer; }
<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>
跨度{
文字装饰:下划线;
颜色:蓝色;
光标:指针;
}
//显示给定页面,隐藏其余页面
功能显示(elementID){
//尝试查找请求的页面,如果未找到,则发出警报
var ele=document.getElementById(elementID);
如果(!ele){
警报(“无此类元素”);
返回;
}
//获取所有页面,循环浏览并隐藏它们
var pages=document.getElementsByClassName('page');
对于(变量i=0;i
第1页内容
第2页内容
第3页内容
所以我的问题是,;如何将文件放入“第1/2/3页内容”中
提前谢谢 如果需要将其他PHP文件与此HTML文件组合,只需将此文件的名称更改为
.PHP
(如果尚未更改)。然后将代码(按处理每个文件的顺序)复制/粘贴到此文件的顶部。一定要用
包围php。如果HTML在PHP文件中,它仍将正确显示
注意:这不是一个好的做法,但它可以完成老师的要求。尝试include(“[path to your file]”)
或包含一次“[文件路径]”代码>
这是javascript而不是PHP你为什么要这么做?你只需要更多的$(“#includedContent”).load(“b.html”)代码>指向正确的页面并使用正确的DIV id加载到中。我的老师让我。。我不知道为什么这取决于项目类型。。。您的老师是要求使用ajax(javascript+服务器端脚本)调用页面,还是只包含文件。如果ajax需要javascript(如果可以使用框架,请尝试jQuery.ajax()),如果只是用php包含文件,请使用Goudgeld1 answer。我认为这并不能回答问题。他要求把所有代码合并成一个文件。这个解决方案仍然需要多个文件。@rick6没错,我没有正确地阅读这个问题,但希望这个答案能帮助其他人:)完全。事实上,我开始写一个与你类似的答案,然后我重新阅读了这个问题并更改了我的答案:)