简单的div密码访问

要实现密码验证正确后隐藏按钮、输入框和“请输入密码”标签的功能,您需要在密码验证成功后,使用JavaScript来修改这些元素的样式。下面是一个简单的示例,展示了如何结合前端和后端(假设后端验证逻辑已经存在)来实现这一功能:

首先,我们需要创建一个简单的HTML表单,其中包含密码输入框、提交按钮以及一个用于显示视频的容器。同时,我们还需要一个“请输入密码”的标签。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Password Protected Video</title>
<script>
function checkPassword() {
    var passwordInput = document.getElementById('password');
    var password = passwordInput.value;
    var submitButton = document.getElementById('submitButton');
    var passwordLabel = document.getElementById('passwordLabel');
    var videoContainer = document.getElementById('videoContainer');
    
    // 这里应该是向后端发送请求验证密码的逻辑
    // 为了简单起见,我们直接在前端模拟验证(不推荐在生产环境中这样做)
    if (password === 'yourSecretPassword') {
        // 如果密码正确
        // 显示视频容器
        videoContainer.style.display = 'block';
        
        // 隐藏输入框、提交按钮和标签
        passwordInput.style.display = 'none';
        submitButton.style.display = 'none';
        passwordLabel.style.display = 'none';
    } else {
        // 如果密码错误
        // 显示错误信息
        alert('密码错误,请重试!');
        
        // 清空输入框
        passwordInput.value = '';
        
        // 重新显示输入框、提交按钮和标签
        passwordInput.style.display = 'block';
        submitButton.style.display = 'block';
        passwordLabel.style.display = 'block';
    }
}
</script>
</head>
<body>

<div>
    <label id="passwordLabel" for="password">请输入密码观看视频:</label>
    <input type="password" id="password" placeholder="密码">
    <button id="submitButton" onclick="checkPassword()">提交</button>
</div>

<div id="videoContainer" style="display: none;">
    <video width="320" height="240" controls>
        <source src="path_to_your_video.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>
</div>

</body>
</html>

在上面的代码中,当用户输入密码并点击提交按钮时,checkPassword函数会被调用。如果密码正确,函数会隐藏密码输入框、提交按钮和“请输入密码”的标签,并显示视频容器。如果密码错误,函数会清空输入框,显示错误提示,并重新显示这些元素。

请注意,这个示例中的密码验证是在客户端进行的,这在实际应用中是不安全的。您应该通过AJAX请求将密码发送到服务器进行验证,并根据服务器的响应来更新页面。这样,密码就不会在客户端以明文形式出现,提高了安全性。

在生产环境中,您应该使用HTTPS来加密客户端和服务器之间的通信,以确保密码传输的安全性。同时,服务器端的密码验证应该使用安全的哈希和盐值存储密码,以防止密码泄露。代码段 小部件

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个简单的漂亮UI的HTML密码访问页面示例,你可以根据自己的需求进行修改: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>密码访问</title> <style> body { background-color: #f1f1f1; font-family: Arial, sans-serif; } h1 { text-align: center; margin-top: 50px; } .container { max-width: 500px; margin: 0 auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 10px; margin-top: 50px; } label { display: block; margin-bottom: 10px; font-size: 16px; color: #333; } input[type="password"] { width: 100%; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; border: none; border-radius: 4px; background-color: #f1f1f1; } button { background-color: #4CAF50; color: #fff; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; width: 100%; margin-top: 10px; } button:hover { background-color: #45a049; } .error-message { color: red; font-size: 14px; margin-top: 10px; } </style> </head> <body> <h1>密码访问</h1> <div class="container"> <form> <label for="password">请输入密码:</label> <input type="password" id="password" name="password" placeholder="请在此输入密码" required> <button type="submit">提交</button> <div class="error-message" id="error-message"></div> </form> </div> <script> var form = document.querySelector("form"); var password = document.querySelector("#password"); var errorMessage = document.querySelector("#error-message"); form.addEventListener("submit", function(event) { event.preventDefault(); if (password.value === "123456") { window.location.href = "secret.html"; } else { errorMessage.innerText = "密码错误,请重新输入!"; password.value = ""; } }); </script> </body> </html> ``` 这个示例使用了一些CSS样式,使页面看起来更加漂亮。当用户输入错误的密码时,会在页面上显示一个红色的错误提示信息。你可以根据自己的需求修改样式和提示信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忘知一切

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值