使用php从索引页面获取文本

时间:2015-10-02 23:45:18

标签: php

有没有办法只从页面获取文字? 对于这里的例子

我有index.php,page1.php,page2.php

现在在index.php我写下面然后我将创建那些page1和page2 ..

<div id="pg1"><a href="page1.php">Hello page 1</a></div>
<div id="pg2"><a href="page2.php">Hello page 2</a></div>

现在在page1和page2上我创建了如下所示的div ..

<div id="getpg1">WHEN page1.php opened, HERE MOST BE TEXT THAT IS ON index.php on div id pg1. get text from that div</div>

<div id="getpg2">WHEN page2.php opened, HERE MOST BE TEXT THAT IS ON index.php on div id pg2. get text from that div</div>
希望你明白。它只是意味着当一个页面打开时,它最多得到我从index.php

指向的文本

1 个答案:

答案 0 :(得分:0)

抱歉,我先花了一点时间在这里修理一下。所以你走了:

<head></head>放在<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".page").on("click",function(e){ e.preventDefault(); var link = $(this).attr("href"); var content = $(this).html(); window.location.href = link + "?content=" + content; }); }); </script> 之间:

<div id="pg1"><a href="page1.php" class="page">Hello page 1</a></div>
<div id="pg2"><a href="page2.php" class="page">Hello page 2</a></div>

将你的div改为:

page1.php

page2.php<div id="getpg1"><?php echo $_GET['content']; ?></div> 上,只需使用:

{{1}}