2011-03-19 68 views
0

我想以后呼应页面上的信息和锚已被点击如果锚点击PHP

<a id="anchor">Information</a> 
<?php 
if(?){ 
echo 'INFORMATION'; 
} 
?> 
+0

我想这将会更好,只需创建一个表单提交按钮并使用css让它看起来像一个锚点 – AndrewFerrara 2011-03-19 19:23:14

回答

0

这就是您可能想要使用AJAX的地方。你经常可以接近这样的:

<a onClick=" $('#output').load('output.php') ">click here</a> 

<div id="output"><!-- This is where the content goes --></div> 

然后定义根据PHP脚本output.php这样的:

<?php 
    echo $whatever; 
?> 

jQuery将随后发出另一个HTTP请求,调用PHP脚本,最后注入它在那里你告诉它(#output div)。

0

由于PHP(你的httpd,正好)不知道什么锚,你会需要处理这与JavaScript。试试jQuery。

0

你不能在PHP中这样做我很害怕。 PHP驻留在服务器上,页面位于客户端(浏览器)上。为了做点什么(除了转到另一个页面)点击时,你需要使用JavaScript。看看jquery

1

我认为你必须在这里使用javascript。 PHP需要刷新页面来处理你​​的echo语句。

1
<a id="anchor" onclick="document.getElementById('information').style.display='block';">Information</a> 
<div id="information" style="display:none"><? echo 'INFORMATION' ?></div> 
0

你不能这样做。

PHP在服务器端工作,因此一旦锚点信息进入客户端浏览器,您将无法在其中执行任何PHP代码。

如果您真的想实现这个目标,有几种解决方法。 i)使用客户端JavaScript。

ii)使用Ajax来制作对服务器端的请求并相应地更新页面。

0

如果你真的想点击进入链接可以使用下面的代码后,显示信息:

<html> 
<title>lasdfjkad</title> 
<head> 
<script type="text/javascript"> 
    function showhide(id){ 
     if (document.getElementById){ 
      obj = document.getElementById(id); 
      if (obj.style.display == "none"){ 
       obj.style.display = ""; 
      } else { 
       obj.style.display = "none"; 
      } 
     } 
    } 
</script> 
</head> 
<body> 
<a href="javascript:showhide('abc');">Show/Hide Details</a> 

<div id="abc" style="display:none;"> 
    your codes...... 
</div> 
</body> 
</html> 

的JavaScript真正的美.....希望这有助于你