【发布时间】: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