简体   繁体   English

PHP 电子邮件验证功能无法回显 JS 警报?

[英]PHP email validation function cannot echo JS alert?

if(isset($_POST['check'])){
    $email =  $_POST['email'];
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) { 
       echo '<script language="javascript">'; 
       echo 'alert(Valid email)';   
       echo '</script>';
    } else { 
       echo '<script language="javascript">'; 
       echo 'alert(Not valid email)';   
       echo '</script>';     
    }
}

i'm trying to show an alert with the result but it's not working.我正在尝试显示带有结果的警报,但它不起作用。 however echo a text working but not JS alert.但是回显文本有效但不是 JS 警报。

why is that?这是为什么? is there another way to do that?还有另一种方法吗?

put '<script type="application/javascript">' instead of '<script language="javascript">''<script type="application/javascript">'而不是'<script language="javascript">'

yout script tag attribute is wrong and also you use alert function wrong.你的脚本标签属性是错误的,你使用的警报功能也是错误的。 change alert(Valid email) to alert("Valid email") and change alert(Not valid email) to alert("Not valid email") .alert(Valid email)更改为alert("Valid email")并将alert(Not valid email)更改为alert("Not valid email")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM