开发者

If anchor is clicked php

I'm trying to echo in开发者_开发技巧formation on a page after and anchor has been clicked

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


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


I think you must use javascript here. PHP would need a page refresh to process your echo statement.


That's where you might want to utilize AJAX. You can often approach it like this:

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

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

Then define the according PHP script output.php like this:

<?php
    echo $whatever;
?>

jQuery will then issue another HTTP request, invoking a PHP script, and finally injects it where you told it to (#output div).


Since PHP (your httpd, exactly) doesn't know anything about anchors, you'll need to handle this with javascript. Try jQuery.


You cant do this in PHP I'm afraid. PHP lives on the server and the page is on your client (browser). In order to do something (other than go to another page) when some clicks, you'll need to use javascript. Look at jquery.


You can't do it like this.

PHP works in the server side, therefore once the anchor information has come to the client browser, you won't be able execute any PHP code there.

There are several workarounds if you really want to achieve that.

i) Use client side JavaScript.

ii) Use Ajax to maker requests to server side and update page accordingly.


If you really want to show the information after clicking into a link can use the following code:

<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>

The real beauty of Javascript.....Hope this help you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜