HTML输入密码后才能访问
时间:2022-10-27
本文章向大家介绍HTML输入密码后才能访问,主要内容包括前言、实现、逼格稍微高点的页面密码框、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。
前言
有小伙伴提了个需求:说网站放 Github Page 上,但不想人人都能访问,怎样用做一个密码加密,比如输入6位密码,密码输入正确自动跳转,错误给出提示?
实现
这个可以用HTML加JS写一个密码输入框,在正确输入密码前阻断内容显示,糊弄下小白还是可以的,画面也比较简洁。
简单实用密码弹出框
在模板或者HTML页头位置加入如下代码,只要是内容显示前就行:
<script language = JavaScript>
function password() {
var testV = 1;
var pass1 = prompt('请输入密码:', '');
while (testV < 3) {
if (!pass1) history.go(-1);
if (pass1 == "123456") {
alert('密码正确!');
break;
}
testV += -1;
var pass1 = prompt('密码错误!请重新输入:');
}
if (pass1 != "password" & testV == 3) history.go(-1);
return " ";
}
document.write(password());
</script>
逼格稍微高点的页面密码框
body里面的代码
<span style="font-family: 黑体;">请输入密码:</span><input id="password" type="password" name="密码输入框"/>
<table width="300" height="300" style="text-align: center;">
<tr>
<td id="1" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">1</td>
<td id="2" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">2</td>
<td id="3" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">3</td>
</tr>
<tr>
<td id="4" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">4</td>
<td id="5" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">5</td>
<td id="6" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">6</td>
</tr>
<tr>
<td id="7" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">7</td>
<td id="8" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">8</td>
<td id="9" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">9</td>
</tr>
</table>
js代码
var password = 123456;
var input = document.getElementById("password");
var td = document.getElementsByTagName("td");
for(var i = 0;i < td.length;i++){
td[i].style.color = "white"
td[i].style.backgroundColor = "#EAEAEA";
td[i].style.borderRadius = "50px";
}
function dodown(obj){
obj.style.backgroundColor = "darkgray";
input.value += obj.id;
}
function doup(obj){
obj.style.backgroundColor = "#EAEAEA";
if(input.value.length == 6){
if(input.value == password){
alert("登录成功");
location.href="https://sobaigu.com";
}else{
alert("密码错误,登录失败")
input.value = null;
}
}
}
function doenter(obj){
obj.style.backgroundColor = "lightgray";
}
function doout(obj){
obj.style.backgroundColor = "#EAEAEA";
}
- 海量数据迁移之使用shell启用多个动态并行(r2笔记81天)
- 使用shell测试历史数据样本(r2笔记80天)
- 【专业技术】编译器的工作原理
- ORA-17500 ODM err的问题排查(r2笔记78天)
- 【专业技术】linux启动流程剖析
- 使用dbms_metadata生成建表语句(r2笔记97天)
- 海量数据迁移之使用分区并行切分导入(r2笔记79天)
- 关于oracle session的简单测试(r2笔记95天)
- 使用utl_file走选择性数据导出(r2笔记95天)
- 使用Linux命令发送邮件(r2笔记94天)
- 如何用python轻松破解wifi密码( 源码 )
- 海量数据迁移之通过shell估算数据量 (r2笔记93天)
- 使用sklearn进行数据挖掘
- 批量转换分区表为普通表(r2笔记92天)
- HTML 教程
- HTML 简介
- html div 标签介绍
- html span 标签介绍
- html a 超链接标签
- HTML Br换行标签介绍
- HTML P段落标签介绍
- HTML br与p标签区别
- Html H 标题标签
- html px em pt长度单位
- HTML form 标签
- HTML radio 单选框
- HTML B 加粗标签
- HTML strong加粗粗体标签
- HTML em 强调标签
- HTML i 斜体标签
- HTML u下划线标签
- HTML s 删除线标签
- Html img 图片标签
- Html上标注sup与下标注sub标签
- HTML nobr 禁止换行标签
- HTML hr 水平线标签
- HTML label 标签
- HTML input 标签
- HTML textarea 标签
- HTML select下拉列表标签
- HTML checkbox 多选框
- HTML font color 标签
- HTML iframe 框架标签
- HTML Table 表格
- HTML dl dt dd 标签
- HTML ol li有序列表标签
- HTML ul li 无序列表标签
- HTML 注释
- CSS 教程
- CSS 简介
- CSS 语法
- CSS Id 和 Class选择器
- CSS 样式的创建
- CSS background 背景介绍
- CSS 文本样式
- CSS font 字体
- CSS A 链接
- CSS ul ol列表样式
- CSS TABLE 样式
- CSS 框模型
- CSS border 边框
- CSS Outlines 轮廓
- CSS 外边距 Margin
- CSS Padding 内边距
- CSS 分组和嵌套选择器
- CSS 尺寸 (Dimension)
- CSS Display 属性
- CSS Position 定位
- CSS Float 浮动
- CSS 水平对齐(Horizontal Align)
- CSS 组合选择符
- CSS 伪类
- CSS 伪元素
- CSS 导航栏
- CSS 下拉菜单
- CSS 图片廊
- CSS 图像透明/不透明
- CSS sprite 图像拼合技术
- CSS 媒体类型
- CSS 属性选择器
- CSS 实例
- PHP信号处理机制的操作代码讲解
- php防止表单重复提交实例讲解
- Python实现封装打包自己写的代码,被python import
- 创建一个 Serverless 应用,真的没有这么难!
- PHP使用mongoclient简单操作mongodb数据库示例
- 基于TensorFlow的CNN实现Mnist手写数字识别
- django rest framework 自定义返回方式
- PHP+Ajax实现的检测用户名功能简单示例
- Yii框架学习笔记之session与cookie简单操作示例
- Ajax+Jpgraph实现的动态折线图功能示例
- Python闭包及装饰器运行原理解析
- Django中Q查询及Q()对象 F查询及F()对象用法
- keras.layer.input()用法说明
- python入门:argparse浅析 nargs='+'作用
- PHP7导出Excel报ERR_EMPTY_RESPONSE解决方法