【问题标题】:toggle multi password visibility - php切换多密码可见性 - php
【发布时间】:2018-01-14 14:00:47
【问题描述】:

我有一个表格,它在 mysql 中存储了许多密码

我们需要隐藏密码,并在需要时点击所需密码

但问题是,通过点击切换,会显示第一个密码

例如:(这不是主要来源)

<!DOCTYPE html>
<html>
<body>

<p>Click the radio button to toggle between password visibility:</p>

Password: <input type="password" value="FakePSW" id="myInput">
<input type="checkbox" onclick="myFunction()">Show Password

<br>
Password: <input type="password" value="FakePSW" id="myInput">
<input type="checkbox" onclick="myFunction()">Show Password
<script>
function myFunction() {
    var x = document.getElementById("myInput");
    if (x.type === "password") {
        x.type = "text";
    } else {
        x.type = "password";
    }
}
</script>

</body>
</html>

我使用了id="'.$row["id"].'",但这还不够

【问题讨论】:

    标签: php passwords toggle


    【解决方案1】:

    对于两个onclick,您指定相同的函数,引用 id myInput。有 2 个具有该名称的 id。

    您不应多次使用相同的 id id="myInput"

    您可以做的是创建唯一的 id 并将其传递给您的函数。

    function myFunction(id) {
      var x = document.getElementById(id);
      if (x.type === "password") {
        x.type = "text";
      } else {
        x.type = "password";
      }
    }
    <!DOCTYPE html>
    <html>
    
    <body>
    
      <p>Click the radio button to toggle between password visibility:</p>
    
      Password: <input type="password" value="FakePSW" id="myInput1">
      <input type="checkbox" onclick="myFunction('myInput1')">Show Password
    
      <br> Password: <input type="password" value="FakePSW" id="myInput2">
      <input type="checkbox" onclick="myFunction('myInput2')">Show Password
    </body>
    
    </html>

    要使用id="'.$row["id"].'",你可以循环你的mysql结果,并为每个结果写下复选框和密码输入。然后你可以使用包含来自mysql的值的id(如果它是唯一的)并使用它而不是'myInput1'

    【讨论】:

    • 感谢您的重播。我使用 id="'.$row["id"].'" 作为 id。 id 必须从 mysql 中读取。但是这个脚本不能这样做。
    • 您可以循环您的 mysql 结果并为每个结果写入复选框和密码输入。然后你可以使用 mysql 的 id 而不是 'myInput1'
    猜你喜欢
    • 1970-01-01
    • 2020-03-29
    • 2022-06-15
    • 1970-01-01
    • 2013-07-12
    • 2017-05-13
    • 2017-05-11
    • 1970-01-01
    • 2012-04-28
    相关资源
    最近更新 更多