gpt4 book ai didi

javascript - 如何使用 for 循环在 javascript 中生成密码?

转载 作者:行者123 更新时间:2023-11-28 01:49:46 25 4
gpt4 key购买 nike

我需要使用for循环将2个随机字母添加到输入到文本框中的字符串中,并在单击按钮时在加密字符串框中返回。因此,例如,如果输入 cat,它可能会像 cynarwtpp 一样返回。我是 for 循环的新手,不确定如何从这里继续,任何帮助将不胜感激。

<script type="text/javascript">


var uncoded_array = uncoded.split("");
var coded_str = "";
var alphabet = new Array("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");













</script>

<form action="">
Enter a String: <input type="text" name="uncoded" ></br>
<input type="button" value="cipher" onClick=document.forms[0].coded.value= ></br>
Encrypted String: <input type="text" name="coded" ></br>

最佳答案

function makecoded()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

这对你有用,会给你一些随机字符串,然后你可以将它添加到任何地方

关于javascript - 如何使用 for 循环在 javascript 中生成密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19827084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com