原生js实现密码输入框值的显示隐藏
网络编程 2021-07-04 18:32www.168986.cn编程入门
这篇文章主要为大家详细介绍了原生js实现密码输入框值的显示隐藏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了js显示隐藏密码输入框值的具体代码,供大家参考,具体内容如下
直接贴上代码
<!DOCTYPE html> <html> <head> <title>password intput demo</title> </head> <style type="text/css"> body{ margin:0px; background-color: white; font-family: 'PT Sans', Helvetica, Arial, sans-serif; text-align: center; color: #A6A6A6; } /*输入框样式,去掉背景阴影模仿原生应用的输入框*/ input{ width: 100%; height: 50px; border:none; padding-left:3px; font-size: 18px; } input:focus { outline: none; } /*显示\隐藏密码图片*/ img{ width: 40px; height: 25px; position: absolute; right: 0px; margin: 15px; } /*登录按钮*/ button{ width: 200px; height: 50px; margin-: 25px; background: #1E90FF; border-radius: 10px; border:none; font-size: 18px; font-weight: 700; color: #fff; } button:hover { background: #79A84B; outline: 0; } /*输入框底部半透明横线*/ .input_block { border-bottom: 1px solid rgba(0,0,0,.1); } /*container*/ #page_container{ margin: 50px; } </style> <body> <div id="page_container"> <!--密码输入框--> <div class="input_block"> <img id="demo_img" onclick="hideShowPsw()" src="visible.png"> <input type="password" id="demo_input" placeholder="Password"/> </div> <button onclick="">Login</button> </div> <script type="text/javascript"> // 这里使用最原始的js语法实现,可对应换成jquery语法进行逻辑控制 var demoImg = document.getElementById("demo_img"); var demoInput = document.getElementById("demo_input"); //隐藏text block,显示password block function hideShowPsw(){ if (demoInput.type == "password") { demoInput.type = "text"; demo_img.src = "invisible.png"; }else { demoInput.type = "password"; demo_img.src = "visible.png"; } } </script> </body> </html>
附上图片:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:Vue.extend构造器的详解
下一篇:extjs简介_动力节点Java学院整理
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程