【问题标题】:How to receive $_SESSION variable as a parameter in onload event如何在 onload 事件中接收 $_SESSION 变量作为参数
【发布时间】:2014-11-29 01:11:52
【问题描述】:

我试图在 onload 事件中调用的 javascript 函数中接收 SESSION 变量作为参数,但没有任何反应。

我的目标是更改最后按下的输入的背景颜色。此输入位于侧边栏上,最后按下的必须更改为不同的颜色,其余的必须变为白色。

如果有其他方法可以做到这一点,我真的很想知道。谢谢。

这是我的代码。

<body onload="identificar_hijo('divGeneral',<?php echo $_SESSION['name_sidebar'];?>)">
<?php //getting the $url of this page?>
<script type="text/javascript">    
    function identificar_hijo(divID,selectedID)
    {
        //using function getChildren() to identify the divs children and change background Colors.
    }
</script>        
    <form name="form1" enctype="multipart/form-data" action="<?php echo $url;?>" method="post">
        <div id="divGeneral" style="margin-left: 5%; margin-right: 5%;">
            <?php
            //saving the session variable
            $_SESSION['name_sidebar'] = $name_sidebar;              
            ?>
                <div id="<?php echo $name_sidebar;?>">
                    <input type="submit" name="<?php echo $name_sidebar;?>" id="<?php echo $name_sidebar;?>">
                </div><?php                
            }?>    
        </div></form></body>

【问题讨论】:

  • 生成的源是什么?看起来您需要在第二个参数周围加上引号,除非它是您存储在会话中的 javascript 变量名。如果您“查看源代码”,您会注意到这一点。

标签: javascript php session


【解决方案1】:

需要将php代码放入'':

<body onload="identificar_hijo('divGeneral','<?php echo $_SESSION['name_sidebar'];?>')">  

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2012-04-08
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    相关资源
    最近更新 更多