javascript 脚本和php?文档.getelementbyid?[已关闭]

0tdrvxhp  于 2023-02-28  发布在  Java
关注(0)|答案(1)|浏览(134)

1小时前关闭。
Improve this question

<?php
if(isset($_POST[`submit`])){
    $password=$_POST[`password`];
    $c_password=$_POST[`c_password`];
    if($password != $c_password){      
      echo  "document.getElementById(`text`).style.display = `block`";
    }
?>
    



<form  method="post" action="">
    <label>   
      Password
    </label>
    <input type="password" name="password"  placeholder="Password" >
    <label>
       Confirm Password
    </label>
    <input type="password" name="c_password" placeholder="Password">    
    <p id="text" style="display:none">
        Incorrect Password
    </p>
    <button type="submit" name="submit">
         Submit
    </button>
</form>

我想如果两个密码不匹配,然后p标记开始显示,但我不知道为什么这是不工作'

xriantvc

xriantvc1#

你会讨厌这个的,你没有关闭你的标签。试试看它现在是否运行。另外PHP不会在你的浏览器本地运行,它需要使用php服务器,如Apache或Nginx来执行。

<?php

if(isset($_POST[`submit`])){
    $password=$_POST[`password`];
    $c_password=$_POST[`c_password`];
    

    if($password != $c_password){
        
      echo  "document.getElementById(`text`).style.display = `block`";
   
    }
?>

下面是一个输入示例

<html>
<form method="POST">
  <label for="password">Password</label>
  <input type="password" id="password" name="password"><br>
  <label for="password2">Confirm Password</label>
  <input type="password" id="password2" name="password2"><br>
  <input type="submit" name="submit" value="Submit">
</form>

    <?php
    if(isset($_POST['submit'])){
        $password = $_POST['password'];
        $password2 = $_POST['password2'];

        if($password != $password2){
            echo "Passwords do not match!";
        }
        else {
            echo "Passwords do match!";
        }
    }
    ?>
</html>

相关问题