duan19740319 2013-05-22 20:56
浏览 55
已采纳

PHP解析地址栏以转发到特定内容

My webpage (www.gagandipsingh.com) is coded mostly on one page, with links calling the following script, which show/hide certain div sections...

    <script type="text/javascript">
    function show() {
        document.getElementById(arguments[0]).style.display='block';
        for (var i = 1; i < arguments.length; i++) {
            // alert(arguments[i]);
             document.getElementById(arguments[i]).style.display='none';
        }
        return false;
    } 
</script>

My question is, is it possible to parse the address bar so that a certain div may be shown/hidden? I found i could get variables (ex: gagandipsingh.com?p=code) so I attempted my requirment with the following...

<?php 
    echo '<script type="text/javascript" src="show_hide.js"></script>';
    if (isset($_GET['p'])) 
    { 
        $page = $_GET['p'];
        if ($page == 'code'){
            echo "show('Code','Media','Home', 'Resume','Contact')";
        }
    } 
    else 
    { 
        echo "Variable not set."; 
    } 
?>

which did not work; the function never gets called, just prints that message. You can see an example of that at http://gagandipsingh.com/test/?p=code

Any advice would be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • du4373 2013-05-22 21:00
    关注

    If you want the function call to be executed instead of just being displayed as part of the web page, you have to enclose it in a <script> tag.

    <?php 
        echo '<script type="text/javascript" src="show_hide.js"></script>';
        if (isset($_GET['p'])) 
        { 
            $page = $_GET['p'];
            if ($page == 'code'){
                echo "<script type='text/javascript'>show('Code','Media','Home', 'Resume','Contact');</script>";
            }
        } 
        else 
        { 
            echo "Variable not set."; 
        } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图