我希望当用户选中我的复选框时,它不会再出现。 但是我的脚本正在运行,因此当脚本第二次运行时,即使用户没有选中我的复选框,也不会显示该脚本。我的所有页面都来自ajax。
if (!in_array('checked', $_SESSION["questy"]))
{
?>
<div id="fifty" style="width:150px; height:25px; float:right" >
<input class="bigcheck" type="checkbox" id="cb" onclick="hiding()"/>
<span style="color:#FFF;font-size:20px;font-family:Arial, Helvetica, sans-serif;font-weight:lighter;">50/50</span>
</div>
<?php }?>
function hiding(){
document.getElementById('<?php echo $ran1;?>').setStyle({"display":"none"});
document.getElementById('<?php echo $ran2;?>').setStyle({"display":"none"});
document.getElementById('fifty').setStyle({"display":"none"});
var c=document.getElementById('cb').getChecked();
alert(c);
if(document.getElementById('cb').getChecked()== true)
{
<?php
$_SESSION["questy"][] = 'checked';
?>
}
}
答案 0 :(得分:0)
你正在混淆服务器端PHP和客户端Javascript。那永远不会奏效。 所有 PHP在页面发送到浏览器之前执行。
您应该做的是使用Ajax将更改的情况提交给服务器,以便它可以在新页面中处理服务器端;或者在提交表格后处理它(服务器端)。