我在一个集团中有一个连接形式,基本上visibility:hidden
当表单被重新加载页面时。
visibility:visible
。但实际上,这段代码不起作用
(如果出现问题,变量$ styleblocconnexion由PHP处理设置)
<script>
$("#connexion-button").click(function(){
$('#bloc-connexion').css("visibility", "visible");
$('#fond-bloc-connexion').css("visibility", "visible");
});
$("#submitconnect").click(function() {
var styleblocconnexion = <?php if(isset($styleblocconnexion)) { echo $styleblocconnexion; } else { echo false; } ?>;
if (styleblocconnexion != false)
{
$('#bloc-connexion').css("visibility", "visible");
$('#fond-bloc-connexion').css("visibility", "visible");
}
});
</script>
这是php traitment中设置$ styleblocconnexion
的代码if(isset($_POST['submitconnect']))
{
$emailconnect = htmlspecialchars($_POST['emailconnect']);
$mdpconnect = sha1($_POST['mdpconnect']);
if(filter_var($emailconnect, FILTER_VALIDATE_EMAIL))
{
$reqemailexist = $bdd->prepare("SELECT * FROM membres WHERE email = ?");
$reqemailexist->execute(array($emailconnect));
$resultemailexist = $reqemailexist->rowCount();
if($resultemailexist == 1)
{
$resultemailexistfetch = $reqemailexist->fetch();
if($mdpconnect == $resultemailexistfetch['mdp'])
{
$_SESSION['id'] = $resultemailexistfetch['id'];
$_SESSION['email'] = $resultemailexistfetch['email'];
header("Location: index.php?id=".$_SESSION['id']);
}
else
{
$msgerreurformconnect = "Mot de passe incorrect";
$styleblocconnexion = "visible";
}
}
else
{
$msgerreurformconnect = "Cette adresse email ne correspond à aucun compte.";
$styleblocconnexion = "visible";
}
}
else
{
$msgerreurformconnect = "Email invalide";
$styleblocconnexion = "visible";
}
}
如您所见,$ styleblocconnexion仅在出现问题时设置。
答案 0 :(得分:0)
我最终用document.ready:
做了$(document).ready(function() {
var styleblocconnexion = "<?php if(isset($styleblocconnexion)) { echo $styleblocconnexion; } else { echo false; } ?>";
if (styleblocconnexion != false)
{
$('#bloc-connexion').css("visibility", "visible");
$('#fond-bloc-connexion').css("visibility", "visible");
}
});
谢谢