gpt4 book ai didi

javascript - PHP如何echo Js自定义alert

转载 作者:行者123 更新时间:2023-11-28 19:54:31 28 4
gpt4 key购买 nike

你好,我从互联网上找到了一个自定义警报,并想在我的 php echo 警报中实现,已经尝试了多种方法,但我找不到正确的语法。请帮忙

我想我需要将“echo”传递给javascript并在您在PHP中调用“echo”时调用该函数,但我没有任何运气

  <script>
function CustomAlert(){
this.render = function(){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = "20px";
dialogbox.style.top = "70px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Login Processado com Sucesso";
document.getElementById('dialogboxbody').innerHTML = "Seja Bem Vindo";
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>';


}
this.ok = function(){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";

}
}
var Alert = new CustomAlert();

</script>

和 PHP:

   <?php
$email=$_POST['email'];
$senha=$_POST['senha'];
$sql = mysql_query("SELECT email, senha FROM clientes WHERE email = '$email' and senha = '$senha'") or die(mysql_error());
$row = mysql_num_rows($sql);
if($row > 0 ) {
session_start();
$_SESSION['email']=$_POST['email'];
$_SESSION['senha']=$_POST['senha'];
echo '<script>';
echo 'Alert.render("Login efetuado com sucesso")';
echo '</script>';
echo "<script>loginsucessfully()</script>";


} else {
echo "Usuario ou senha invalidos";
echo "<script>loginfailed()</script>";
}

?>

最佳答案

将变量从 PHP 传递到 Javascript:

var something = <?php echo $something; ?>;

顺便说一下,PHP 标签中的分号不是必需的,因为它只是一行代码;这只是风格问题。

关于javascript - PHP如何echo Js自定义alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22823579/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com