溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

JS隨機(jī)密碼生成算法

發(fā)布時(shí)間:2020-10-17 13:46:49 來(lái)源:腳本之家 閱讀:179 作者:apple_2021 欄目:web開(kāi)發(fā)

本文實(shí)例為大家分享了JS生成隨機(jī)密碼的具體代碼,供大家參考,具體內(nèi)容如下

題目:

輸入一個(gè)正整數(shù)n,生成n個(gè)隨機(jī)密碼,其中包括數(shù)字,大小寫(xiě)字母。

代碼:

<!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>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI