JS随机密码生成算法
更新时间:2019年09月23日 09:09:41 作者:apple_2021
这篇文章主要为大家详细介绍了JS随机密码生成算法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了JS生成随机密码的具体代码,供大家参考,具体内容如下
题目:
输入一个正整数n,生成n个随机密码,其中包括数字,大小写字母。
代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> div{ width: 300px; height: 100px; background-color: lightblue; overflow: auto; } </style> </head> <body> <input type="text"> <button>生成</button> <div class="end"></div> <script> var oTn = document.getElementsByTagName("input")[0]; var oBtn = document.getElementsByTagName("button")[0]; var oDiv = document.querySelector(".end"); var password = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o", "p","q","r","s","t","u","v","w","x","y","z","A","B","C","D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S", "T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9" ]; function pass(length){ var Str = ""; for(var i = 0 ; i<length;i++){ Str += password[Math.floor(Math.random()*password.length)]; } return Str; } oBtn.onclick = function(){ oDiv.innerHTML = pass(oTn.value); } </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
使用 JScript 创建 .exe 或 .dll 文件的方法
JScript 是由微软开发的活动脚本语言,基于 ECMAScript 规范实现。Internet Explorer 中的 JavaScript,实际上是指 JScript。2011-07-07使用JavaScript实现一个简单的待办事项列表todo-list
这篇文章主要为大家详细介绍了如何使用JavaScript实现一个简单的待办事项列表todo-list,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下2024-04-04
最新评论