如何使用php文件访问包含的元素
我设置了模板php脚本,以便轻松地对文件进行更改。我有index.php作为主页,还有两个php脚本footer.php和header.php。我在index.php中包含了其中两个。我的问题是可以从header.php访问footer.php中的html元素吗 index.php如何使用php文件访问包含的元素,php,Php,我设置了模板php脚本,以便轻松地对文件进行更改。我有index.php作为主页,还有两个php脚本footer.php和header.php。我在index.php中包含了其中两个。我的问题是可以从header.php访问footer.php中的html元素吗 index.php header.php $(文档).ready(函数(){ $(“#footerDiv”).css('display','none'); }); footer.php $(文档).ready(函数(){ $(
header.php
$(文档).ready(函数(){
$(“#footerDiv”).css('display','none');
});
footer.php
$(文档).ready(函数(){
$(“#footediv”).css('display','block');
});
我想从header.php访问这个div
首先创建index.php文件,如下所示
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
然后像这样创建header.php文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
$(文档).ready(函数(){
$(“#footerDiv”).css('display','none');
});
然后像这样创建footer.php文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
我想从header.php访问这个div
最后运行index.php,然后可以看到页脚内容隐藏首先创建index.php文件,如下所示
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
然后像这样创建header.php文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
$(文档).ready(函数(){
$(“#footerDiv”).css('display','none');
});
然后像这样创建footer.php文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="header"><?php require "header.php" ?></div>
<div class="footer"><?php require "footer.php" ?></div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#footerDiv").css('display','none');
});
</script>
<div id="footerDiv">
<p>I wanted to access this div from header.php</p>
</div>
我想从header.php访问这个div
最后运行index.php,然后您可以看到页脚内容隐藏包括您的文件,然后您可以访问可能您希望在web软件工程中有一个更好的开端。像一些小的MVC代码,包括你的文件,然后你可以访问可能你想在网络软件工程更好的开始。就像一些小的MVC代码一样,我添加了一个代码,请你看一下,然后说点什么#Shafiqlyou想访问的意思是你想从header中获取文本?是的,就像我在header.php中做的那样,我想更改div的样式,我已经尝试过了,但不适合我,当我运行index.php.im时,对不起,我没有得到你所做的更改,一切都和我贴的一样。。。你能给我描述一下吗?我已经测试过了,并且工作得很好,我相信它会工作的。我添加了一个代码,请你看一下,然后说一些话,你想访问的意思是你想从标题中获取文本吗?是的,就像我在header.php中做的那样,我想更改div的样式,我已经尝试过了,但没有为我工作,当我运行index.php.im抱歉,但我没有得到你所做的更改,一切都与我发布的一样。。。你能给我描述一下吗……我已经测试过了,并且在我的领域工作得很好,我相信它会工作的